From 97064db2a41d89575286095241bcb16428e606fd Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Wed, 23 Jan 2019 18:14:45 +0100 Subject: [PATCH] Restart python3 fix, stop and restart python2 working again --- cps/server.py | 12 ++++++++++-- cps/updater.py | 4 ++-- cps/web.py | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cps/server.py b/cps/server.py index 53c4c859..da7b487c 100644 --- a/cps/server.py +++ b/cps/server.py @@ -25,7 +25,7 @@ import signal import web try: - from gevent.pywsgi import WSGIServer + from gevent.piwsgi import WSGIServer from gevent.pool import Pool from gevent import __version__ as geventVersion gevent_present = True @@ -37,6 +37,7 @@ except ImportError: gevent_present = False + class server: wsgiserver = None @@ -63,6 +64,7 @@ class server: self.wsgiserver = WSGIServer(('', web.ub.config.config_port), web.app, spawn=Pool(), **ssl_args) web.py3_gevent_link = self.wsgiserver self.wsgiserver.serve_forever() + except SocketError: try: web.app.logger.info('Unable to listen on \'\', trying on IPv4 only...') @@ -110,6 +112,9 @@ class server: web.helper.global_WorkerThread.stop() sys.exit(1) + # ToDo: Somehow caused by circular import under python3 refactor + if sys.version_info > (3, 0): + self.restart = web.py3_restart_Typ if self.restart == True: web.app.logger.info("Performing restart of Calibre-Web") web.helper.global_WorkerThread.stop() @@ -126,12 +131,15 @@ class server: sys.exit(0) def setRestartTyp(self,starttyp): - self.restart=starttyp + self.restart = starttyp + # ToDo: Somehow caused by circular import under python3 refactor + web.py3_restart_Typ = starttyp def killServer(self, signum, frame): self.stopServer() def stopServer(self): + # ToDo: Somehow caused by circular import under python3 refactor if sys.version_info > (3, 0): if not self.wsgiserver: if gevent_present: diff --git a/cps/updater.py b/cps/updater.py index e679268c..9905a1e8 100644 --- a/cps/updater.py +++ b/cps/updater.py @@ -216,7 +216,7 @@ class Updater(threading.Thread): item_path = os.path.join(destination, item[1:]) if os.path.isdir(item_path): logging.getLogger('cps.web').debug("Delete dir " + item_path) - shutil.rmtree(item_path) + shutil.rmtree(item_path, ignore_errors=True) else: try: logging.getLogger('cps.web').debug("Delete file " + item_path) @@ -237,7 +237,7 @@ class Updater(threading.Thread): return False def _stable_version_info(self): - return {'version': '0.6.0'} + return {'version': '0.6.0'} # Current version def _nightly_available_updates(self, request_method): tz = datetime.timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone) diff --git a/cps/web.py b/cps/web.py index 6ea6e42d..bbec773c 100644 --- a/cps/web.py +++ b/cps/web.py @@ -132,7 +132,9 @@ except ImportError: # Global variables current_milli_time = lambda: int(round(time.time() * 1000)) gdrive_watch_callback_token = 'target=calibreweb-watch_files' +# ToDo: Somehow caused by circular import under python3 refactor py3_gevent_link = None +py3_restart_Typ = False EXTENSIONS_UPLOAD = {'txt', 'pdf', 'epub', 'mobi', 'azw', 'azw3', 'cbr', 'cbz', 'cbt', 'djvu', 'prc', 'doc', 'docx', 'fb2', 'html', 'rtf', 'odt'} EXTENSIONS_CONVERT = {'pdf', 'epub', 'mobi', 'azw3', 'docx', 'rtf', 'fb2', 'lit', 'lrf', 'txt', 'htmlz'}