I am attempting to deploy a Flask-Socket.io app using Gunicorn and eventlet as per the documentation: https://flask-socketio.readthedocs.io/en/latest/deployment.html.
I have both Gunicorn and eventlet installed, but when I run gunicorn --worker-class eventlet -w 1 myapp:app, I get the following error which prints out repeatedly until I kill the process.
[2023-08-22 19:51:01 -0400] [57647] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
worker.init_process()
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/gunicorn/workers/geventlet.py", line 143, in init_process
super().init_process()
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/gunicorn/workers/base.py", line 142, in init_process
self.run()
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/gunicorn/workers/geventlet.py", line 173, in run
eventlet.sleep(1.0)
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/eventlet/greenthread.py", line 36, in sleep
hub.switch()
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/eventlet/hubs/hub.py", line 313, in switch
return self.greenlet.switch()
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/eventlet/hubs/hub.py", line 365, in run
self.wait(sleep_time)
File "/Users/alexpalacios/Documents/Projects/spotify-game/venv/lib/python3.8/site-packages/eventlet/hubs/kqueue.py", line 98, in wait
result = self._control([], self.MAX_EVENTS, seconds)
File "/Users/alexpalacios/Documents/Projects/spotify-game/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
Below is my code and version info for dependencies.
myapp.py:
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@socketio.on('message')
def handle_message(data):
print('received message: ' + data)
if __name__ == '__main__':
socketio.run(app)
version info:
Python==3.8.8
Flask==2.3.2
Flask-SocketIO==5.3.5
eventlet==0.33.3
gunicorn==21.2.0
The app runs fine using python myapp.py, but my end goal is to deploy an actual app on Render.com, which is why I want to make Gunicorn work.
The server will start up when I call eventlet.monkey_patch() and run the command gunicorn -w 1 myapp:app, and I am able to connect from Postman, however the connection is terminated after a short time and I receive this error message.
[2023-08-22 20:10:52 -0400] [57992] [CRITICAL] WORKER TIMEOUT (pid:57994) [2023-08-22 20:10:52 -0400] [57994] [INFO] Worker exiting (pid: 57994) [2023-08-22 20:10:53 -0400] [57992] [ERROR] Worker (pid:57994) was sent SIGKILL! Perhaps out of memory? [2023-08-22 20:10:53 -0400] [58006] [INFO] Booting worker with pid: 58006
I would appreciate any advice, since the code I am working with is very simple so it seems I am missing a key concept here. Thank you!
EDIT: I fixed the problem by deleting my virtual environment and reinstalling dependencies.
old requirements.txt
annotated-types==0.5.0
anyio==3.7.1
async-timeout==4.0.2
bidict==0.22.1
blinker==1.6.2
certifi==2023.5.7
charset-normalizer==3.2.0
click==8.1.6
cycler==0.11.0
dnspython==2.4.2
eventlet==0.33.3
exceptiongroup==1.1.2
Flask==2.3.2
Flask-Cors==4.0.0
Flask-SocketIO==5.3.5
fonttools==4.40.0
greenlet==2.0.2
gunicorn==21.2.0
h11==0.14.0
httpcore==0.17.3
idna==3.4
importlib-metadata==6.8.0
importlib-resources==6.0.0
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
kiwisolver==1.4.4
MarkupSafe==2.1.3
marshmallow==3.20.1
matplotlib==3.7.2
numpy==1.24.4
packaging==23.1
Pillow==10.0.0
pluggy==1.2.0
pydantic-core==2.4.0
pymongo==4.4.1
pyparsing==3.0.9
pytest==7.4.0
python-dateutil==2.8.2
python-dotenv==1.0.0
python-engineio==4.5.1
python-socketio==5.8.0
python-vlc==3.0.18122
redis==4.6.0
requests==2.31.0
six==1.16.0
sniffio==1.3.0
spotipy==2.23.0
tomli==2.0.1
typing-extensions==4.7.1
urllib3==2.0.4
Werkzeug==2.3.6
zipp==3.15.0
New requirements.txt
async-timeout==4.0.3
bidict==0.22.1
blinker==1.6.2
certifi==2023.7.22
charset-normalizer==3.2.0
click==8.1.7
dnspython==2.4.2
eventlet==0.33.3
flask==2.3.3
Flask-Cors==4.0.0
Flask-SocketIO==5.3.5
greenlet==2.0.2
gunicorn==21.2.0
idna==3.4
importlib-metadata==6.8.0
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
marshmallow==3.20.1
packaging==23.1
pymongo==4.5.0
python-dotenv==1.0.0
python-engineio==4.6.1
python-socketio==5.8.0
redis==5.0.0
requests==2.31.0
six==1.16.0
spotipy==2.23.0
urllib3==2.0.4
werkzeug==2.3.7
zipp==3.16.2