0

I have a Flask app (technically Dash) that use longish DB queries up to 5 minutes. When I run with the development server (by using python app2.py), the app and DB queries run fine. But when I run the app with Gunicorn, no matter how I tweak the settings, the DB query times out, and the app does not run correctly.

I know that unlike the Flask development server, Gunicorn generally tries to avoid long I/O requests (like a DB query), but no matter how I change the timeout and worker type settings, nothing seems to fix the problem. I tried adding the number of workers and changing the worker type to gevent as I was researching that's better at handling I/O requests, but there is no change in behavior. Does anyone know what would solve this or where to even look? Below is the config I'm using to run Gunicorn, and also the failure message in the log when the DB query times out and spins endlessly. Also, I am running this on Ubuntu Server using SQLAlchemy in my Flask app to connect to a PostgreSQL DB. Thanks and let me know if you need any more details!

gunicorn --bind 127.0.0.1:8050 --workers 4 --worker-class gevent --timeout 600 app2:server

[29512] [CRITICAL] WORKER TIMEOUT (pid:29536)
[29512] [WARNING] Worker with pid 29536 was terminated due to signal 9
geckels1
  • 347
  • 1
  • 3
  • 13
  • `gevent` worker with `gunicorn` will need some `specific settings` for work correctly, try this SO threads https://stackoverflow.com/questions/60035871/flask-timeout-when-serve-using-gunicorn, and gunicorn doc. https://docs.gunicorn.org/en/stable/design.html – RedNam Oct 19 '21 at 04:15
  • 1
    I saw it before, and I am having basically the identical problem in that SO thread including having it work with uWSGI. I also tried in Gunicorn with ordinary Sync workers and gthread workers but got the same behavior. Very frustrating since Gunicorn is such a common Python WSGI server that it feels like this should work, and I'm missing some simple setting. – geckels1 Oct 19 '21 at 05:02
  • After how long time is the worker killed? – Petr Blahos Oct 19 '21 at 13:51
  • About 6 minutes. – geckels1 Oct 19 '21 at 22:10
  • Did you figure out the problem ? – Shiko Mar 29 '22 at 03:19
  • I had to close the DB connection and reopen it every time I wanted to run this particular query. The connection would idle in PostgreSQL and this is what solved it. Not an elegant solution, but it's now working. – geckels1 Apr 03 '22 at 04:41

0 Answers0