Python Forum

Full Version: Flask Rest API - fire and forget
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to call a flask rest api to do some processing, but the processing is taking longer than the rest api timeout (2 minutes), and I have no control over the timeout value (shared hosting).

Is there any python functionality that I can use to perform a fire-and-forget type function call, i.e. get the rest api code to call a function to do the processing in the background, but return from the rest api call immediately (I don't need a response), so as not to hit the timeout, and allow other rest api calls to continue being processed?

Note: Celery/RabbitMQ/Redis, etc, is not an option.
Hi,

what you are looking for is concurrency. As you do not need a result / return value from the data processing, it is fairly easy. Just launch the actual data processing in a separate process and connect it to the process running Flask by a queue. Once the API receives a call and data, put the data into the queue and Flask can respond without running into a timeout.

Regards, noisefloor
Hi noisefloor, Excellent!

I had been thinking about this for hours, but I couldn't see the wood for the trees! Now I'm having flashbacks to multiprocessing in OS/2 Think LOL

Regards