From e90dcc6e5cd478e5f27a97520ccd4a0299bb9ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Piboub=C3=A8s?= Date: Sat, 5 Sep 2015 16:29:31 +0200 Subject: [PATCH] Start HTTP server only once --- rtv/oauth.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rtv/oauth.py b/rtv/oauth.py index f696918..1dfcc67 100644 --- a/rtv/oauth.py +++ b/rtv/oauth.py @@ -11,7 +11,7 @@ from six.moves import configparser from . import config from .curses_helpers import show_notification, prompt_input -from tornado import gen, ioloop, web +from tornado import gen, ioloop, web, httpserver from concurrent.futures import ThreadPoolExecutor __all__ = ['token_validity', 'OAuthTool'] @@ -67,6 +67,8 @@ class OAuthTool(object): (r'/auth', AuthHandler), ], template_path='rtv/templates') + self.http_server = None + def get_config_fp(self): HOME = os.path.expanduser('~') XDG_CONFIG_HOME = os.getenv('XDG_CONFIG_HOME', @@ -115,8 +117,9 @@ class OAuthTool(object): self.open_config(update=True) # If no previous OAuth data found, starting from scratch if not self.config.has_section('oauth') or not self.config.has_option('oauth', 'refresh_token'): - # Start HTTP server and listen on port 65000 - self.callback_app.listen(65000) + if self.http_server is None: + self.http_server = httpserver.HTTPServer(self.callback_app) + self.http_server.listen(65000) # Generate a random UUID hex_uuid = uuid.uuid4().hex