From 60e8d37c1ff1f4b242bbb5361f400750eae9d857 Mon Sep 17 00:00:00 2001 From: yi suo Date: Wed, 26 May 2021 17:17:33 +0800 Subject: [PATCH 1/3] fix jp_ws_fetch not work by its own #441 --- jupyter_server/pytest_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jupyter_server/pytest_plugin.py b/jupyter_server/pytest_plugin.py index f187687535..892828ba5f 100644 --- a/jupyter_server/pytest_plugin.py +++ b/jupyter_server/pytest_plugin.py @@ -336,7 +336,7 @@ def client_fetch(*parts, headers={}, params={}, **kwargs): @pytest.fixture -def jp_ws_fetch(jp_serverapp, jp_auth_header, jp_http_port, jp_base_url): +def jp_ws_fetch(jp_serverapp, http_server_client, jp_auth_header, jp_http_port, jp_base_url): """Sends a websocket request to a test server. The fixture is a factory; it can be called like From 515e740fb03e2c3e28ade9500798881fde12eccb Mon Sep 17 00:00:00 2001 From: yi suo Date: Mon, 31 May 2021 17:58:28 +0800 Subject: [PATCH 2/3] add a method for create a task immediately after io_loop is ready --- jupyter_server/serverapp.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 2dc2af39df..0be8a0b90f 100755 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -2338,12 +2338,25 @@ def start_ioloop(self): pc = ioloop.PeriodicCallback(lambda : None, 5000) pc.start() try: + self.start_task_when_ioloop_ready() self.io_loop.start() except KeyboardInterrupt: self.log.info(_i18n("Interrupted...")) finally: self._cleanup() + startup_tasks = List( + help=_i18n("""functions which created when io_loop is created""") + ) + + def start_task_when_ioloop_ready(self): + """run init tasks when io_loop is ready""" + for task in self.startup_tasks: + try: + self.io_loop.call_later(0, task) + except Exception: + self.log.error("not supported task:{}".format(task)) + def start(self): """ Start the Jupyter server app, after initialization From 42928651258894a11b866c586dde77116bb49f9e Mon Sep 17 00:00:00 2001 From: yi suo Date: Thu, 17 Jun 2021 15:22:09 +0800 Subject: [PATCH 3/3] create io_loop earlier to solve 'enable a way to run a task when an io_loop is created #531' --- jupyter_server/serverapp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index 2dc2af39df..dd9939ca5d 100755 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -2052,6 +2052,7 @@ def initialize(self, argv=None, find_extensions=True, new_httpserver=True, start self.init_webapp() self.init_terminals() self.init_signal() + self.init_ioloop() self.load_server_extensions() self.init_mime_overrides() self.init_shutdown_no_activity() @@ -2331,7 +2332,6 @@ def _cleanup(self): def start_ioloop(self): """Start the IO Loop.""" - self.io_loop = ioloop.IOLoop.current() if sys.platform.startswith('win'): # add no-op to wake every 5s # to handle signals that may be ignored by the inner loop @@ -2344,6 +2344,10 @@ def start_ioloop(self): finally: self._cleanup() + def init_ioloop(self): + """init self.io_loop so that an extension can use it by io_loop.call_later() to create background tasks""" + self.io_loop = ioloop.IOLoop.current() + def start(self): """ Start the Jupyter server app, after initialization