'Gunicorn + Flask + Docker python app hosted on Azure Container Instances returns SystemExit: 1

I deployed a web app on GPU enabled ACI (Azure Container Instance) using Gunicorn + Flask + Docker. This app runs a couple of pytorch models (one of them being easyOCR and the other being YOLOv5).

The app was working fine, but then started to throw exception for all incoming requests. similar to the following

  File "/usr/local/lib/python3.7/site-packages/werkzeug/wrappers/request.py", line 540, in json
    return self.get_json()
  File "/usr/local/lib/python3.7/site-packages/werkzeug/wrappers/request.py", line 575, in get_json
    data = self.get_data(cache=cache)
  File "/usr/local/lib/python3.7/site-packages/werkzeug/wrappers/request.py", line 405, in get_data
    rv = self.stream.read()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/http/body.py", line 215, in read
    data = self.reader.read(1024)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/http/body.py", line 130, in read
    data = self.unreader.read()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/http/unreader.py", line 37, in read
    d = self.chunk()
  File "/usr/local/lib/python3.7/site-packages/gunicorn/http/unreader.py", line 64, in chunk
    return self.sock.recv(self.mxchunk)
  File "/usr/local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 203, in handle_abort
    sys.exit(1)
SystemExit: 1

gunicorn parameters

gunicorn wsgi:app --bind  0.0.0.0:443 --log-level=info --workers=3 --reload --timeout 120

ACI specs

4 Cores
8 GB RAM
1 GPU Tesla K80
Linux environment

Followed this blog to create the app.

I tried adjusting the timeout parameter following many other posts such as this but didn't resolve the issue.

What caused this error and how do I fix this?



Solution 1:[1]

Thank you @amro_ghoneim for updating the resolution in the comments. Posting it as an answer to help other community members.

To get rid of those exceptions, change worker type to gevent.

  • To pause your application code for extended periods of time make use of gevent worker or -k gevent on the command line.

  • In order to add gevent worker, add below commands in your config file:

pip install gevent
gunicon .... --worker-class gevent

Reference :

Gunicorn worker timeout error - Stack Overflow

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RukminiMr-MT