From 7f563449c82ff7a4e7afb3771f15f257a9a181a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Tue, 12 Feb 2019 06:28:09 -0500 Subject: [PATCH] Catch sooner if gevent is not installed. --- bazarr/main.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/bazarr/main.py b/bazarr/main.py index 79b883afb..d2d3e67a9 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -2,7 +2,20 @@ bazarr_version = '0.7.2' -from gevent import monkey +# Try to import gevent and exit if it's not available. This one is required to use websocket. +try: + from gevent import monkey +except ImportError as e: + logging.exception('BAZARR require gevent Python module to be installed using pip.') + try: + stop_file = open(os.path.join(args.config_dir, "bazarr.stop"), "w") + except Exception as e: + logging.error('BAZARR Cannot create bazarr.stop file.') + else: + stop_file.write('') + stop_file.close() + os._exit(0) + monkey.patch_all() import gc @@ -26,10 +39,10 @@ from init import * from update_db import * from notifier import update_notifier from logger import configure_logging, empty_log +import gevent from gevent.pywsgi import WSGIServer from geventwebsocket import WebSocketError from geventwebsocket.handler import WebSocketHandler -# from cherrypy.wsgiserver import CherryPyWSGIServer from io import BytesIO from six import text_type from beaker.middleware import SessionMiddleware @@ -80,20 +93,6 @@ if "PYCHARM_HOSTED" in os.environ: else: bottle.ERROR_PAGE_TEMPLATE = bottle.ERROR_PAGE_TEMPLATE.replace('if DEBUG and', 'if') -# Install gevent under user directory if it'S not already available. This one is required to use websocket. -try: - import gevent -except ImportError as e: - logging.exception('BAZARR require gevent Python module to be installed using pip.') - try: - stop_file = open(os.path.join(args.config_dir, "bazarr.stop"), "w") - except Exception as e: - logging.error('BAZARR Cannot create bazarr.stop file.') - else: - stop_file.write('') - stop_file.close() - os._exit(0) - # Reset restart required warning on start conn = sqlite3.connect(os.path.join(args.config_dir, 'db', 'bazarr.db'), timeout=30) c = conn.cursor()