@@ -218,9 +218,9 @@ class NotebookClient(LoggingConfigurable):
218
218
@default ('kernel_manager_class' )
219
219
def _kernel_manager_class_default (self ):
220
220
"""Use a dynamic default to avoid importing jupyter_client at startup"""
221
- from jupyter_client import KernelManager
221
+ from jupyter_client import AsyncKernelManager
222
222
223
- return KernelManager
223
+ return AsyncKernelManager
224
224
225
225
_display_id_map = Dict (
226
226
help = dedent (
@@ -317,8 +317,8 @@ async def start_new_kernel_client(self, **kwargs):
317
317
----------
318
318
kwargs :
319
319
Any options for `self.kernel_manager_class.start_kernel()`. Because
320
- that defaults to KernelManager , this will likely include options
321
- accepted by `KernelManager .start_kernel()``, which includes `cwd`.
320
+ that defaults to AsyncKernelManager , this will likely include options
321
+ accepted by `AsyncKernelManager .start_kernel()``, which includes `cwd`.
322
322
323
323
Returns
324
324
-------
@@ -332,15 +332,15 @@ async def start_new_kernel_client(self, **kwargs):
332
332
if self .km .ipykernel and self .ipython_hist_file :
333
333
self .extra_arguments += ['--HistoryManager.hist_file={}' .format (self .ipython_hist_file )]
334
334
335
- self .km .start_kernel (extra_arguments = self .extra_arguments , ** kwargs )
335
+ await self .km .start_kernel (extra_arguments = self .extra_arguments , ** kwargs )
336
336
337
337
self .kc = self .km .client ()
338
338
self .kc .start_channels ()
339
339
try :
340
340
await self .kc .wait_for_ready (timeout = self .startup_timeout )
341
341
except RuntimeError :
342
342
self .kc .stop_channels ()
343
- self .km .shutdown_kernel ()
343
+ await self .km .shutdown_kernel ()
344
344
raise
345
345
self .kc .allow_stdin = False
346
346
return self .kc
@@ -470,8 +470,8 @@ async def _poll_for_reply(self, msg_id, cell, timeout, task_poll_output_msg):
470
470
timeout = max (0 , deadline - monotonic ())
471
471
except Empty :
472
472
# received no message, check if kernel is still alive
473
- self ._check_alive ()
474
- self ._handle_timeout (timeout , cell )
473
+ await self ._check_alive ()
474
+ await self ._handle_timeout (timeout , cell )
475
475
476
476
async def _poll_output_msg (self , parent_msg_id , cell , cell_index ):
477
477
while True :
@@ -494,18 +494,18 @@ def _get_timeout(self, cell):
494
494
495
495
return timeout
496
496
497
- def _handle_timeout (self , timeout , cell = None ):
497
+ async def _handle_timeout (self , timeout , cell = None ):
498
498
self .log .error ("Timeout waiting for execute reply (%is)." % timeout )
499
499
if self .interrupt_on_timeout :
500
500
self .log .error ("Interrupting kernel" )
501
- self .km .interrupt_kernel ()
501
+ await self .km .interrupt_kernel ()
502
502
else :
503
503
raise CellTimeoutError .error_from_timeout_and_cell (
504
504
"Cell execution timed out" , timeout , cell
505
505
)
506
506
507
- def _check_alive (self ):
508
- if not self .kc .is_alive ():
507
+ async def _check_alive (self ):
508
+ if not await self .kc .is_alive ():
509
509
self .log .error ("Kernel died while waiting for execute reply." )
510
510
raise DeadKernelError ("Kernel died" )
511
511
@@ -518,10 +518,10 @@ async def _wait_for_reply(self, msg_id, cell=None):
518
518
try :
519
519
msg = await self .kc .shell_channel .get_msg (timeout = self .shell_timeout_interval )
520
520
except Empty :
521
- self ._check_alive ()
521
+ await self ._check_alive ()
522
522
cummulative_time += self .shell_timeout_interval
523
523
if timeout and cummulative_time > timeout :
524
- self ._handle_timeout (timeout , cell )
524
+ await self ._handle_timeout (timeout , cell )
525
525
break
526
526
else :
527
527
if msg ['parent_header' ].get ('msg_id' ) == msg_id :
@@ -800,7 +800,7 @@ def execute(nb, cwd=None, km=None, **kwargs):
800
800
The notebook object to be executed
801
801
cwd : str, optional
802
802
If supplied, the kernel will run in this directory
803
- km : KernelManager , optional
803
+ km : AsyncKernelManager , optional
804
804
If supplied, the specified kernel manager will be used for code execution.
805
805
kwargs :
806
806
Any other options for ExecutePreprocessor, e.g. timeout, kernel_name
0 commit comments