-
-
Notifications
You must be signed in to change notification settings - Fork 952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration to Gevent #2029
Migration to Gevent #2029
Changes from 2 commits
30ae7dc
e411aaf
b48f08b
3bcd1f0
b4a80b8
9351bb9
eccf60b
258f227
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,12 @@ | |
|
||
__version__ = '0.45.8.1' | ||
|
||
from gevent import monkey | ||
monkey.patch_all(thread=False) | ||
from gevent.pywsgi import WSGIServer | ||
from distutils.util import strtobool | ||
from json.decoder import JSONDecodeError | ||
|
||
import eventlet | ||
import eventlet.wsgi | ||
import getopt | ||
import os | ||
import signal | ||
|
@@ -22,24 +23,28 @@ | |
# Only global so we can access it in the signal handler | ||
app = None | ||
datastore = None | ||
# Using global only for shutdown. | ||
cd_server = None | ||
|
||
# Parent wrapper or OS sends us a SIGTERM/SIGINT, do everything required for a clean shutdown | ||
def sigshutdown_handler(_signo, _stack_frame): | ||
global app | ||
global datastore | ||
global cd_server | ||
name = signal.Signals(_signo).name | ||
print(f'Shutdown: Got Signal - {name} ({_signo}), Saving DB to disk and calling shutdown') | ||
datastore.sync_to_json() | ||
print(f'Sync JSON to disk complete.') | ||
# This will throw a SystemExit exception, because eventlet.wsgi.server doesn't know how to deal with it. | ||
# Solution: move to gevent or other server in the future (#2014) | ||
datastore.stop_thread = True | ||
app.config.exit.set() | ||
sys.exit() | ||
cd_server.stop() | ||
cd_server.close() | ||
print('Shutdown Success', file=sys.stderr) | ||
|
||
def main(): | ||
global datastore | ||
global app | ||
global cd_server | ||
|
||
datastore_path = None | ||
do_cleanup = False | ||
|
@@ -153,11 +158,13 @@ def hide_referrer(response): | |
|
||
if ssl_mode: | ||
# @todo finalise SSL config, but this should get you in the right direction if you need it. | ||
eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen((host, port), s_type), | ||
certfile='cert.pem', | ||
keyfile='privkey.pem', | ||
server_side=True), app) | ||
|
||
ssl_args = { | ||
'certfile' : 'cert.pem', | ||
'keyfile' : 'privkey.pem', | ||
'server_side' : True, | ||
} | ||
else: | ||
eventlet.wsgi.server(eventlet.listen((host, int(port)), s_type), app) | ||
|
||
ssl_args = {} | ||
sock = WSGIServer.get_listener((host, port), family=s_type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested with Netstat, ipv6 also works(?). FYI, |
||
cd_server = WSGIServer(sock, app, **ssl_args) | ||
Constantin1489 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cd_server.serve_forever() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
eventlet>=0.33.3 # related to dnspython fixes | ||
gevent | ||
feedgen~=0.9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
also means we can maybe un-pin some package versions.. i wonder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eventlet/eventlet#781 is that 'dnspython' problem i believe, but actually it may not be a 'thing' anymore |
||
flask-compress | ||
# 0.6.3 included compatibility fix for werkzeug 3.x (2.x had deprecation of url handlers) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for logging.