Strange Behavior with RabbitMQ and Flask-SocketIO #2005
-
Describe the bug To Reproduce
and write a rabbitmq client like this to test the app:
Expected behavior Logs
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
I test it on python 3.10, with packages as below: |
Beta Was this translation helpful? Give feedback.
-
You are using the Flask reloader, which runs two instances of your app. That means that you have two RabbitMQ callbacks that are active, and two of each global variable that you define. Could you please repeat the test using Flask in production mode instead? |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for your prompt reply! I decided to learn and use Flask after reading your blog tutorial. However, I haven't delved deep into the underlying mechanisms and logic, nor do I know about its reloader mechanism. I'm testing in a production environment, but I still have a question. If multiple workers are started by the server in the production environment, will they also have independent global variables and SocketIO connections? Could similar issues arise? |
Beta Was this translation helpful? Give feedback.
-
@njbinbin Yes, each process is independent of the others and will have its own set of globals. |
Beta Was this translation helpful? Give feedback.
-
I installed eventlet package, set app.config['FLASK_ENV'] = 'production', then start app with:
or
everything is OK :) |
Beta Was this translation helpful? Give feedback.
You are using the Flask reloader, which runs two instances of your app. That means that you have two RabbitMQ callbacks that are active, and two of each global variable that you define.
Could you please repeat the test using Flask in production mode instead?