diff --git a/cps/server.py b/cps/server.py index 9c5993aa..53c4c859 100644 --- a/cps/server.py +++ b/cps/server.py @@ -61,11 +61,13 @@ class server: self.wsgiserver= WSGIServer(('0.0.0.0', web.ub.config.config_port), web.app, spawn=Pool(), **ssl_args) else: 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...') self.wsgiserver = WSGIServer(('0.0.0.0', web.ub.config.config_port), web.app, spawn=Pool(), **ssl_args) + web.py3_gevent_link = self.wsgiserver self.wsgiserver.serve_forever() except (OSError, SocketError) as e: web.app.logger.info("Error starting server: %s" % e.strerror) @@ -130,6 +132,12 @@ class server: self.stopServer() def stopServer(self): + if sys.version_info > (3, 0): + if not self.wsgiserver: + if gevent_present: + self.wsgiserver = web.py3_gevent_link + else: + self.wsgiserver = IOLoop.instance() if self.wsgiserver: if gevent_present: self.wsgiserver.close() diff --git a/cps/web.py b/cps/web.py index 2a0e4f5a..6ea6e42d 100644 --- a/cps/web.py +++ b/cps/web.py @@ -132,6 +132,7 @@ except ImportError: # Global variables current_milli_time = lambda: int(round(time.time() * 1000)) gdrive_watch_callback_token = 'target=calibreweb-watch_files' +py3_gevent_link = None 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'}