Flask-socketio: message queue doesn't work

Created on 1 Mar 2016  路  6Comments  路  Source: miguelgrinberg/Flask-SocketIO

Hi,

I've got something like that

socketio = SocketIO(app, message_queue='redis://x.x.x.x')

my redis server works fine but the code blocks in this line like it can't connect to the redis server or something. When I use a bad url like "redis://test" I've got the proper error messages. But in this case, it's juste looping infinetly. I enabled the debug but no message is outputed.

app.debug = True
...
socketio.run(app, host='0.0.0.0', debug=True)

Any idea ?
Thanks

question

Most helpful comment

The problem is that many of the functions and classes in the Python standard library are not compatible with the asynchronous model that eventlet uses. Eventlet has replacements to all these functions that need to be monkey patched in the standard library, so that when the redis code wants to use one of these incompatible functions it gets the eventlet version.

Monkey patching is done as follows:

import eventlet
eventlet.monkey_patch()

You want to add these two lines at the top of your main application module, ideal above all other imports.

All 6 comments

Are you using eventlet or gevent? If you are, did you monkey patch the standard library?

Hi, I'm using eventlet. I didn't monkey patch it. I honestly don't know what it means.

The problem is that many of the functions and classes in the Python standard library are not compatible with the asynchronous model that eventlet uses. Eventlet has replacements to all these functions that need to be monkey patched in the standard library, so that when the redis code wants to use one of these incompatible functions it gets the eventlet version.

Monkey patching is done as follows:

import eventlet
eventlet.monkey_patch()

You want to add these two lines at the top of your main application module, ideal above all other imports.

Yes thanks, I just patched it ! It works perfectly !
Do you know how to turn off the logs that say something like that (6196) accepted ('127.0.0.1', 59358) ?
Even if I do app.debug = False and socketio.run(app, host='0.0.0.0', debug=False), it still displays these type of messages.

Thanks very much, I got the same problem and fixed it by this issue :)

@cookkkie Those log lines are emitted by eventlet's wsgi server (see here). Unfortunately, SocketIO's run() function doesn't pass down the debug option into the server object when instatiating it (here), since that option is previously removed from kwargs (here).

I just tested this, and you can get rid of the logging by passing in a logger object and configuring it to not output debug messages:

logger = logging.getLogger('eventlet')
logger.setLevel(logging.INFO) # or logging.WARNING, logging.ERROR, etc.
socketio.run(...., log=logger)

Another option is to use a different webserver (e.g. gunicorn) when running locally, but that comes with its own downsides.

Was this page helpful?
0 / 5 - 0 ratings