Hi Miguel, I'm developing a Flask Rest API. I'm trying to use web sockets to push messages from backend to frontend.
I can run the project locally, and everything works fine. But when I try to use Gunicorn to start up the project, the project does not work properly.
This is my code / entry point
wsgi.py file
#pylint: disable=wrong-import-position, wrong-import-order
import eventlet
eventlet.monkey_patch()
import os
import time
from flask import g, request
from flask_socketio import SocketIO
from app import create_app, db
app = create_app(os.environ.get("FLASK_ENV", 'development'))
socketio = SocketIO(app, async_mode='eventlet')
if __name__ == '__main__':
socketio.run(app, host="0.0.0.0", port=5000, debug=True, use_reloader=True, log_output=True)
Running locally
export FLASK_ENV=development
export FLASK_APP=wsgi.py
export DEBUG=1
python wsgi.py
Terminal output
Server initialized for eventlet.
* Restarting with stat
Server initialized for eventlet.
* Debugger is active!
* Debugger PIN: 124-101-814
(73886) wsgi starting up on http://0.0.0.0:5000
But when I try to use Gunicorn as it is described here
gunicorn -k eventlet -w 1 wsgi:app -b :5000
Terminal output
[2021-06-07 19:26:26 -0300] [74095] [INFO] Starting gunicorn 20.1.0
[2021-06-07 19:26:26 -0300] [74095] [INFO] Listening at: http://0.0.0.0:5000 (74095)
[2021-06-07 19:26:26 -0300] [74095] [INFO] Using worker: eventlet
[2021-06-07 19:26:26 -0300] [74097] [INFO] Booting worker with pid: 74097
Server initialized for eventlet.
Traceback (most recent call last):
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/hubs/hub.py", line 476, in fire_timers
timer()
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/hubs/timer.py", line 59, in __call__
cb(*args, **kw)
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/greenthread.py", line 221, in main
result = function(*args, **kwargs)
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/gunicorn/workers/geventlet.py", line 78, in _eventlet_serve
conn, addr = sock.accept()
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/greenio/base.py", line 230, in accept
self._trampoline(fd, read=True, timeout=self.gettimeout(), timeout_exc=_timeout_exc)
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/greenio/base.py", line 208, in _trampoline
return trampoline(fd, read=read, write=write, timeout=timeout,
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/hubs/__init__.py", line 155, in trampoline
listener = hub.add(hub.READ, fileno, current.switch, current.throw, mark_as_closed)
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/hubs/kqueue.py", line 53, in add
self._control([event], 0, 0)
File "/home/jony/flask_app/venv/lib/python3.8/site-packages/eventlet/hubs/kqueue.py", line 39, in _control
return self.kqueue.control(events, max_events, timeout)
OSError: [Errno 9] Bad file descriptor
[2021-06-07 19:26:27 -0300] [74097] [ERROR] Exception in worker process
Any idea, what I'm doing wrong?
Thanks in advance,
Juan R
Let me attach my requirements.txt, in case it helps.
requirements.txt
Hi Miguel, I'm developing a Flask Rest API. I'm trying to use web sockets to push messages from backend to frontend.
I can run the project locally, and everything works fine. But when I try to use Gunicorn to start up the project, the project does not work properly.
This is my code / entry point
wsgi.py file
Running locally
Terminal output
But when I try to use Gunicorn as it is described here
Terminal output
Any idea, what I'm doing wrong?
Thanks in advance,
Juan R
Let me attach my requirements.txt, in case it helps.
requirements.txt