multithreading - flask application with background threads -


i creating flask application, 1 request need run long running job not required wait on ui. create thread , send message ui. thread calculate , update database. but, ui see message upon submit. below implementation, running thread , sending output ui not prefer. how can run thread in background?

@app.route('/somejob') def index():     t1 = threading.thread(target=long_running_job)     t1.start()     return 'scheduled job'  def long_running_job     #some long running processing here 

how can make thread t1 run background , send message in return?

the best thing stuff use message broker. there excellent software in python world meant doing this:

both excellent choices.

it's never idea spawn thread way you're doing it, can cause issues processing incoming requests, among other things.

if take @ celery or rq getting started guides, they'll walk through doing proper way!


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -