socketio.run() locking code execution #2072
-
In my application I have additional code after socketio.run() which is not being executed. Can socketio be run separately so code can continue to execute? I've tried with eventlet, gevent, and default "threading". The sockets do seem to work, it's just that I want to run additional things afterward; is it possible? My code is like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you can run the server in a background thread. Something like this: if __name__ == "__main__":
socketio.start_background_task(socketio.run, app, port=5555, debug=True)
print("this will print") But now you have a problem, because this will cause the application to end. Whatever you do after starting the server must keep the script from exiting. |
Beta Was this translation helpful? Give feedback.
Yes, you can run the server in a background thread. Something like this:
But now you have a problem, because this will cause the application to end. Whatever you do after starting the server must keep the script from exiting.