mmartinez
mmartinez

Reputation: 91

Using gevent-socketio paster integration causes my application to be unresponsive

I am writing a Pyramid application that relies on gevent-socketio and redis. However, I noticed that when I navigate away from the view that establishes the socket.io connection, my application becomes unresponsive. In order to try and isolate the issue, I created another bare-bones application and discovered that using pubsub.listen() was causing the issue:

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

The way I'm starting up my application is as follows:

pserve --reload development.ini

However, I can only get my application to work if use use the serve.py from the examples:

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()

Unfortunatey this is rather cumbersome for development as I lose --reload functionality. Ideally I'd like to use the paster integration entry point

Another thing I noticed is that the gevent-sockectio paster integration does not monkey patch gevent, whereas the examples server.py does.

How can I get pserve --reload to work with gevent-socketio?

I've uploaded my test application to github: https://github.com/m-martinez/iotest

Upvotes: 1

Views: 476

Answers (2)

mmartinez
mmartinez

Reputation: 91

With no success using egg:gevent-socketio#paster, I ended up using gunicorn with watchdog to achieve what I wanted for development:

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

This is what my [server:main] section looks like:

[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

Upvotes: 0

Krayons
Krayons

Reputation: 240

Under [server:main] in your ini file.

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

If you get an error make sure you using the latest version of gevent-socketio.

Upvotes: 0

Related Questions