1+ import asyncio
2+
13from dask .distributed import Client as DaskClient
24from jupyter_core .paths import jupyter_data_dir
35from jupyter_server .extension .application import ExtensionApp
@@ -72,15 +74,11 @@ def initialize_settings(self):
7274
7375 environments_manager = self .environment_manager_class ()
7476
75- asyncio_loop = self .serverapp .io_loop .asyncio_loop
76- dask_client_future = asyncio_loop .create_task (self ._get_dask_client ())
77-
7877 scheduler = self .scheduler_class (
7978 root_dir = self .serverapp .root_dir ,
8079 environments_manager = environments_manager ,
8180 db_url = self .db_url ,
8281 config = self .config ,
83- dask_client_future = dask_client_future ,
8482 )
8583
8684 job_files_manager = self .job_files_manager_class (scheduler = scheduler )
@@ -89,28 +87,8 @@ def initialize_settings(self):
8987 environments_manager = environments_manager ,
9088 scheduler = scheduler ,
9189 job_files_manager = job_files_manager ,
92- dask_client_future = dask_client_future ,
9390 )
9491
9592 if scheduler .task_runner :
96- asyncio_loop .create_task (scheduler .task_runner .start ())
97-
98- async def _get_dask_client (self ):
99- """Creates and configures a Dask client."""
100- return DaskClient (processes = False , asynchronous = True )
101-
102- async def stop_extension (self ):
103- """Called by the Jupyter Server when stopping to cleanup resources."""
104- try :
105- await self ._stop_extension ()
106- except Exception as e :
107- self .log .error ("Error while stopping Jupyter Scheduler:" )
108- self .log .exception (e )
109-
110- async def _stop_extension (self ):
111- """Closes the Dask client if it exists."""
112- if "dask_client_future" in self .settings :
113- dask_client : DaskClient = await self .settings ["dask_client_future" ]
114- self .log .info ("Closing Dask client." )
115- await dask_client .close ()
116- self .log .info ("Dask client closed." )
93+ loop = asyncio .get_event_loop ()
94+ loop .create_task (scheduler .task_runner .start ())
0 commit comments