Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gunicorn worker getting restarted itself after long API calls

I have a flask application which is running using Gunicorn.

This flask application have an API which takes two hours to complete.

If the same API is called twice after a 30 minutes gap between two , then the process handling the first API call is getting restarted after the second API call.

Example: Initial process starts with API_1 After 30 mins API_1 is called again , then the process handling previous API_1 call is getting restarted.

Command used to start the Gunicorn server:

nohup gunicorn --bind 0.0.0.0:5000 --workers=8 run:app --timeout 7200  --preload> output.log& 

No of core : 8

I am not facing any issue while running flask in development mode.

Any idea why its behaving like this ?

like image 221
Joby Wilson Mathews Avatar asked Jan 18 '26 19:01

Joby Wilson Mathews


1 Answers

You can use other types of worker. Your current worker type is sync. If you want to send a long request probably you must use a thread worker or async worker.

nohup gunicorn --bind 0.0.0.0:5000 -k gevent run:app

Refer to this document

like image 156
NavaneethaKrishnan Avatar answered Jan 21 '26 09:01

NavaneethaKrishnan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!