Flask-Socketio: namespace keyerror., get list of connected clients
You are iterating over a private data structure of package gevent-socketio
, so unexpected things can happen.
I do not know the internals of this package to tell you why this happens, but I think a much safer approach would be for you to build your own list of connected clients. You can add and remove clients to your list in the connect and disconnect handlers. I think something like this will work:
clients = []@socketio.on('connect', namespace='/test')def connect(): clients.append(request.namespace)@socketio.on('disconnect', namespace='/test')def disconnect(): clients.remove(request.namespace)