when i have this, from the docs:
mgr = socketio.KombuManager('redis://')
sio = socketio.Server(client_manager=mgr)
the second line hangs. it works without the keyword argument. I have made sure that reddis and rabbitmq are running and have tried variations on the URI on the first line without success.
can anyone offer any suggestions on diagnosing the problem?
Does socketio.RedisManager('redis://') work? What about socketio.KombuManager('amqp://')?
no, neither. neither specifying locahost, port etc. in either case.
my complete script is currently:
#!/usr/bin/env python
import socketio
print 1
mgr = socketio.RedisManager('redis://')
print 2
sio = socketio.Server(client_manager=mgr)
print 3
where python is the name of python2.7
ah, i've just discovered that the missing '3' does get printed if i uninstall eventlet. slightly problematic since i was using it for the server
uninstalling eventlet and deploying with gevent looks like a suitable workaround
alas no. with gevent it gets as far as serve_forever() before blocking, but none of the @sio.on callbacks fire unless i remove client_manager
I think I know what the problem is.
When you are using eventlet you have to monkey patch the python library, if not redis will not work. Try this:
import eventlet
eventlet.monkey_patch()
mgr = socketio.KombuManager('redis://')
sio = socketio.Server(client_manager=mgr)
With gevent, it's like this:
from gevent import monkey
monkey.patch_all()
mgr = socketio.KombuManager('redis://')
sio = socketio.Server(client_manager=mgr)
success. thank you. this section could perhaps be expanded a little in that regard http://python-socketio.readthedocs.org/en/latest/#id1
Yes, I wrote a documentation issue on Flask-SocketIO regarding this problem. :)
I think I know what the problem is.
When you are using eventlet you have to monkey patch the python library, if not redis will not work. Try this:
import eventlet eventlet.monkey_patch() mgr = socketio.KombuManager('redis://') sio = socketio.Server(client_manager=mgr)With gevent, it's like this:
from gevent import monkey monkey.patch_all() mgr = socketio.KombuManager('redis://') sio = socketio.Server(client_manager=mgr)
I am having problem when I use like this..
import eventlet
eventlet.monkey_patch()
mgr = socketio.KombuManager('amqp://')
sio = socketio.Server(client_manager=mgr)
socketio handshake fails with status code 400
GET /socket.io/?EIO=3&transport=websocket&sid=9b1d580299f34e53abafb61ec4652b1f HTTP/1.1" 400 122 0.000181
If I remove monkey_patch socketio connects normally and I can emit web socket messages.
Any Idea why web socket connection fails when I use monkey_patch?
Please find below the simple program I am trying to execute
import socketio
import eventlet
eventlet.monkey_patch()
mgr = socketio.KombuManager('amqp://')
sio = socketio.Server(client_manager=mgr)
app = socketio.WSGIApp(sio)
def read_notifications_task():
while True:
sio.sleep(5)
message = next(mgr._listen())
handle_message(message)
@sio.event
def connect(sid, environ):
print('connected ', sid, environ)
@sio.event
def disconnect(sid):
print('disconnected ', sid)
def handle_message(message):
print('received message ', message)
sio.emit('message_received', message)
if __name__ == '__main__':
eventlet.wsgi.server(eventlet.listen(('0.0.0.0', 9093)), app)
eventlet.spawn(read_notifications_task)
Most helpful comment
I think I know what the problem is.
When you are using eventlet you have to monkey patch the python library, if not redis will not work. Try this:
With gevent, it's like this: