I have a pretty straightforward question, but I haven’t found a very straightforward answer: When should I use start_background_task() over starting a Python thread “normally”? Flask-SocketIO documentation states:
This function returns an object compatible with the Thread class in the Python standard library. The start() method on this object is already called by this function.
It doesn’t say much about whether it’s necessary to use this over initializing and starting a thread per the threading module.
The reason start_background_task() exists is that depending on what web server you use the threading model changes. For example, if you are using eventlet or gevent, then a background task needs to be started as a greenlet, not as a Thread instance.
If you use start_background_task() you will be guaranteed that a task object that is compatible with your environment will be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With