Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask Rest API - fire and forget
#1
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.
Reply
#2
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
Reply
#3
Big Grin 
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  REST API using flask - limit connection? korenron 1 1,276 Feb-05-2023, 06:48 PM
Last Post: noisefloor
  Simple flask rest api problem cancerboi 4 2,840 Jan-29-2020, 03:10 PM
Last Post: brighteningeyes
  Flask Error-Could not build url for endpoint 'index'. Did you forget to specify value Prince_Bhatia 0 10,322 Feb-25-2019, 05:52 AM
Last Post: Prince_Bhatia
  Flask rest api How to retrieve json request raysefo 4 6,135 Jan-20-2019, 06:46 PM
Last Post: raysefo
  Python Flask REST API vndywarhol 1 2,998 Sep-28-2018, 12:43 PM
Last Post: thomasp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020