1
+ import asyncio
2
+
1
3
from dask .distributed import Client as DaskClient
2
4
from jupyter_core .paths import jupyter_data_dir
3
5
from jupyter_server .extension .application import ExtensionApp
@@ -72,15 +74,11 @@ def initialize_settings(self):
72
74
73
75
environments_manager = self .environment_manager_class ()
74
76
75
- asyncio_loop = self .serverapp .io_loop .asyncio_loop
76
- dask_client_future = asyncio_loop .create_task (self ._get_dask_client ())
77
-
78
77
scheduler = self .scheduler_class (
79
78
root_dir = self .serverapp .root_dir ,
80
79
environments_manager = environments_manager ,
81
80
db_url = self .db_url ,
82
81
config = self .config ,
83
- dask_client_future = dask_client_future ,
84
82
)
85
83
86
84
job_files_manager = self .job_files_manager_class (scheduler = scheduler )
@@ -89,28 +87,8 @@ def initialize_settings(self):
89
87
environments_manager = environments_manager ,
90
88
scheduler = scheduler ,
91
89
job_files_manager = job_files_manager ,
92
- dask_client_future = dask_client_future ,
93
90
)
94
91
95
92
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