Python Forum
Flask Rest API - fire and forget - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Flask Rest API - fire and forget (/thread-39348.html)



Flask Rest API - fire and forget - MorganSamage - Feb-03-2023

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.


RE: Flask Rest API - fire and forget - noisefloor - Feb-03-2023

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


RE: Flask Rest API - fire and forget - MorganSamage - Feb-04-2023

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