Skip to content

Commit

Permalink
Switching to gevent and upgrading psycopg to 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Rmarieta committed Jan 22, 2024
1 parent 4a60b7d commit 49296d7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
6 changes: 3 additions & 3 deletions flask/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ USER flaskuser
# CMD python application.py run --debug --host 0.0.0.0

# without Flask-SocketIO
# CMD gunicorn --access-logfile '-' --workers 3 --threads 4 --bind 0.0.0.0:5000 application:application
# with Flask-SocketIO, gunicorn does not support sticky sessions, workers must be 1. eventlet takes care of multi-threading, threads must be 1
CMD gunicorn --access-logfile '-' --log-level 'debug' --worker-class eventlet --workers 1 --bind 0.0.0.0:5000 application:application
# CMD gunicorn --access-logfile '-' -w 3 -t 4 -b 0.0.0.0:5000 application:application
# with Flask-SocketIO, gunicorn does not support sticky sessions, workers must be 1. gevent takes care of multi-threading, threads must be 1
CMD gunicorn --access-logfile '-' --log-level 'debug' -k gevent -w 1 -b 0.0.0.0:5000 application:application
2 changes: 1 addition & 1 deletion flask/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create_app():
r"/*": {"origins": []}
})

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://{username}:{password}@{host}:{port}/{database}'.format(
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg://{username}:{password}@{host}:{port}/{database}'.format(
username=os.environ['RDS_USERNAME'],
password=os.environ['RDS_PASSWORD'],
host=os.environ['RDS_HOSTNAME'],
Expand Down
6 changes: 2 additions & 4 deletions flask/application.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import eventlet

# perform monkey patching for eventlet
eventlet.monkey_patch()
from gevent import monkey
monkey.patch_all()

from flask import Flask, jsonify
from app import create_app, db, socketio
Expand Down
28 changes: 16 additions & 12 deletions flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
async-timeout==4.0.3
bidict==0.22.1
blinker==1.7.0
click==8.1.7
dnspython==2.4.2
eventlet==0.34.2
Flask==2.2.3
Flask-Cors==3.0.10
dnspython==2.5.0
Flask==3.0.1
Flask-Cors==4.0.0
Flask-SocketIO==5.3.6
Flask-SQLAlchemy==3.0.3
greenlet==2.0.2
Flask-SQLAlchemy==3.1.1
gevent==23.9.1
greenlet==3.0.3
gunicorn==21.2.0
h11==0.14.0
importlib-metadata==7.0.1
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.3
Jinja2==3.1.3
MarkupSafe==2.1.4
packaging==23.2
psycopg2-binary==2.9.6
psycopg==3.1.17
psycopg-binary==3.1.17
python-engineio==4.8.2
python-socketio==5.11.0
redis==5.0.1
simple-websocket==1.0.0
six==1.16.0
SQLAlchemy==2.0.9
SQLAlchemy==2.0.25
typing_extensions==4.9.0
Werkzeug==2.2.3
Werkzeug==3.0.1
wsproto==1.2.0
zipp==3.15.0
zipp==3.17.0
zope.event==5.0
zope.interface==6.1

0 comments on commit 49296d7

Please sign in to comment.