Socketio to zmq in background thread works in Werkzeug development environment but blocks in deployment #2147
-
|
I have niche application which involves hooking lasers up to websockets so people can play vector arcade games projected on public buildings using their phone as an interface. It's worked really well when I run it with the werkzeug development environment: python -m flask run --host=192.168.1.2 --port=5000 But now I'm getting close to deployment and I'd like to run it either with gunicorn or ideally just the socketio.run(app) method and get it all set up as unit file for systemd. When I try this though (i.e. just python app.py) my background thread code blocks and the web server hangs till I ctrl c and I get Like I said it works in the development environment. I know this is something to do with the background task I'm using to create a persistent connection via zmq with my c++ app to send data back to clients from the game. Does anyone have any clues how to make the background thread non blocking in any of the socketio.run() scenarios? I would prefer to not use the dev environment in production for my event.... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Cool application! Let me clarify something that maybe isn't completely clear. Socket.IO does not have a web server. You always have to choose a web server to run your application on. If you don't explicitly pick a web server, then a web server is chosen for you from what's installed in your virtualenv. From the errors you shared, it looks like you are using the gevent web server. Are you sure your code and all your dependencies are compatible with gevent? And if they are, have you monkey patched the Python standard library so that it does not block? If you have issues with gevent, then your other option in practice is to use a multithreaded web server like Werkzeug, but production ready. You can use gunicorn in threaded mode, for example. This should be the closest to the Werkzeug solution, but you will need to configure gunicorn with enough threads to handle all your clients. Each client consumes one thread exclusively. |
Beta Was this translation helpful? Give feedback.
I think I just about parsed this from the deployment section of the docs. From what I understand just running
python app.pyis inherently more secure than using the Werkzeug setup, is this right? I just wanted to make the warning go away before it goes public facing. I'm not anticipating more than 20 connections at a time and the whole thing is running on raspberry pi 5 seeming very well. I haven't got Nginx or anything at the front just python running flask and So…