I am creating a flask application, for one request I need to run some long running job which is not required to wait on the UI. I will create a thread and send a message to
Check out Flask-Executor which uses concurrent.futures in the background and makes your life very easy.
from flask_executor import Executor
executor = Executor(app)
@app.route('/someJob')
def index():
executor.submit(long_running_job)
return 'Scheduled a job'
def long_running_job
#some long running processing here
This not only runs jobs in the background but gives them access to the app context. It also provides a way to store jobs so users can check back in to get statuses.