【问题标题】:gunicorn can't run with more than one workergunicorn 不能与一个以上的工人一起运行
【发布时间】: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 模型具有相同的行为。

标签: python gunicorn gevent


【解决方案1】:

您不能使用相同的端口。我们遇到了这个问题并花了一些时间来解决。

WebSocket 绑定到一个端口,每个 gunicorn 都会尝试在同一个端口中创建 WS。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-24
    • 2023-01-05
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 2020-07-17
    • 2016-06-28
    相关资源
    最近更新 更多