Flask-SocketIO start_background_task() with Gunicorn workers #2114
Unanswered
GuyShalomCyberRidge
asked this question in
Q&A
Replies: 1 comment
-
You should run your background task separately, not as part of your Flask application. That way it will be started independently from the web server and will not be affected by the horizontal scaling you want to do. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey! 🐶
I have a background task that regularly updates a DB and sends data to the client. Currently
start_background_task()
runs in mycreate_app()
function on init.I'm trying to move from Flask Dev server & threads, to a Gunicorn & gevent configuration.
My problem comes when running Gunicorn with multiple workers.
Let's say I run 4 workers, now I have 4 background tasks running, all doing the same stuff and hogging my CPU usage. 😒
Is there a "correct" way of handling regular interval tasks like this?
Do I even have the right idea in using Gunicorn-gevent, or should I go for another approach instead?
Any help would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions