【问题标题】:Using gevent-socketio paster integration causes my application to be unresponsive使用 gevent-socketio paste 集成导致我的应用程序无响应
【发布时间】:2014-04-08 03:18:45
【问题描述】:

我正在编写一个 Pyramid 应用程序,它依赖于 gevent-socketioredis。但是,我注意到当我离开建立 socket.io 连接的视图时,我的应用程序变得无响应。为了尝试隔离问题,我创建了另一个准系统应用程序,发现使用 pubsub.listen() 导致了问题:

class TestNamespace(BaseNamespace):

    def initialize(self):
        self.spawn(self.emitter)

    def emitter(self):
        client = redis.pubsub()
        client.subscribe('anything')
        for broadcast in client.listen():
            if broadcast['type'] != 'message':
                continue

我启动应用程序的方式如下:

pserve --reload development.ini

但是,如果使用 examples 中的 serve.py,我只能让我的应用程序工作:

import os.path

from socketio.server import SocketIOServer
from pyramid.paster import get_app
from gevent import monkey; monkey.patch_all()

HERE = os.path.abspath(os.path.dirname(__file__))

if __name__ == '__main__':

    app = get_app(os.path.join(HERE, 'development.ini'))
    print 'Listening on port http://0.0.0.0:8080 and on port 10843 (flash policy server)'

    SocketIOServer(('0.0.0.0', 8080), app,
        resource="socket.io", policy_server=True,
        policy_listener=('0.0.0.0', 10843)).serve_forever()

不幸的是,这对于开发来说相当麻烦,因为我失去了 --reload 功能。理想情况下,我想使用paster integration entry point

我注意到的另一件事是gevent-sockectio paster integration 没有猴子补丁 gevent,而示例 server.py 有。

如何让 pserve --reload 与 gevent-socketio 一起工作?

我已将我的测试应用程序上传到 github:https://github.com/m-martinez/iotest

【问题讨论】:

    标签: pyramid gevent-socketio redis-py


    【解决方案1】:

    在您的 ini 文件中的 [server:main] 下。

    use = egg:gevent-socketio#paster
    transports = websocket, xhr-multipart, xhr-polling
    policy_server = True
    host = 0.0.0.0
    port = 6543
    

    如果您遇到错误,请确保您使用的是最新版本的 gevent-socketio。

    【讨论】:

    • 我使用的是 github 上的当前版本,而不是 pypi 上的版本。我尝试了你的建议(除了我使用port = 8080),它仍然给我带来问题。不过感谢您的关注!
    • 这很奇怪。看看youtube.com/watch?v=zhh_N5pmHBY。他一步一步完成设置。
    【解决方案2】:

    使用 egg:gevent-socketio#paster 没有成功,我最终使用 gunicornwatchdog 来实现我想要的开发:

      watchmedo auto-restart \
                --pattern "*.py;*.ini" \
                --directory ./iotest/ \
                --recursive \
                -- \
                gunicorn --paste ./iotest/development.ini
    

    这就是我的 [server:main] 部分的样子:

    [server:main]
    use = egg:gunicorn#main
    worker_class = socketio.sgunicorn.GeventSocketIOWorker
    host = 0.0.0.0
    port = 8080
    debug = True
    logconfig = %(here)s/development.ini
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多