Skip to content
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

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 17 additions & 10 deletions changedetectionio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

__version__ = '0.45.13'

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
Expand All @@ -23,11 +22,14 @@
# 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
logger.critical(f'Shutdown: Got Signal - {name} ({_signo}), Saving DB to disk and calling shutdown')
datastore.sync_to_json()
Expand All @@ -36,11 +38,14 @@ def sigshutdown_handler(_signo, _stack_frame):
# 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)
Copy link
Contributor Author

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.


def main():
global datastore
global app
global cd_server

datastore_path = None
do_cleanup = False
Expand Down Expand Up @@ -184,11 +189,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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with Netstat, ipv6 also works(?). FYI, http://[::1]:5000

cd_server = WSGIServer(sock, app, **ssl_args)
Constantin1489 marked this conversation as resolved.
Show resolved Hide resolved
cd_server.serve_forever()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eventlet>=0.33.3 # related to dnspython fixes
gevent
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to dnspython fixes

also means we can maybe un-pin some package versions.. i wonder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh the dnspython I will apply it later.

Copy link
Owner

Choose a reason for hiding this comment

The 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

feedgen~=0.9
flask-compress
# 0.6.3 included compatibility fix for werkzeug 3.x (2.x had deprecation of url handlers)
Expand Down