diff --git a/jupyter_collaboration/app.py b/jupyter_collaboration/app.py index 22378b77..4eacdc79 100644 --- a/jupyter_collaboration/app.py +++ b/jupyter_collaboration/app.py @@ -85,8 +85,16 @@ def initialize_handlers(self): # We are temporarily initializing the store here because the # initialization is async self.store = self.ystore_class(log=self.log) - loop = asyncio.get_event_loop() - loop.run_until_complete(self.store.initialize()) + + try: + loop = asyncio.get_event_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + task = loop.create_task(self.store.initialize()) + if not loop.is_running(): + loop.run_until_complete(task) # self.settings is local to the ExtensionApp but here we need # the global app settings in which the file id manager will register diff --git a/jupyter_collaboration/stores/utils.py b/jupyter_collaboration/stores/utils.py index 79f6b7f3..6e8d71e4 100644 --- a/jupyter_collaboration/stores/utils.py +++ b/jupyter_collaboration/stores/utils.py @@ -1,6 +1,7 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. + class YDocNotFound(Exception): pass