【发布时间】:2017-01-17 07:22:42
【问题描述】:
我有一个简单的 websocket 应用程序,例如 main.py
当我尝试使用一名工作人员启动它时,
gunicorn -w 1 -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" main:EchoApplication
没有问题。
如果我将w参数增加到大于1,例如-w 20,childs开始崩溃,
error: [Errno 48] Address already in use: ('127.0.0.1', 8100)
有什么想法吗?附上源码
from geventwebsocket import WebSocketServer, WebSocketApplication, Resource
import time
class EchoApplication(WebSocketApplication):
def on_open(self):
print "Connection opened"
def on_message(self, message):
self.ws.send('Let me take a sleep')
time.sleep(10)
self.ws.send(message)
def on_close(self, reason):
print reason
WebSocketServer(
('127.0.0.1', 8100),
Resource({'/': EchoApplication})
).serve_forever()
【问题讨论】:
-
你不能在同一个端口上运行 20 个应用程序,每个应用程序都需要一个唯一的端口
-
@iScrE4m 该死!我认为它与 apache 的 pre fork 模型具有相同的行为。