@@ -414,6 +414,8 @@ def setup_kernel(self, **kwargs):
414
414
When control returns from the yield it stops the client's zmq channels, and shuts
415
415
down the kernel.
416
416
"""
417
+ cleanup_kc = kwargs .pop ('cleanup_kc' , True )
418
+
417
419
# Can't use run_until_complete on an asynccontextmanager function :(
418
420
if self .km is None :
419
421
self .start_kernel_manager ()
@@ -423,7 +425,8 @@ def setup_kernel(self, **kwargs):
423
425
try :
424
426
yield
425
427
finally :
426
- self ._cleanup_kernel ()
428
+ if cleanup_kc :
429
+ self ._cleanup_kernel ()
427
430
428
431
@asynccontextmanager
429
432
async def async_setup_kernel (self , ** kwargs ):
@@ -435,7 +438,7 @@ async def async_setup_kernel(self, **kwargs):
435
438
When control returns from the yield it stops the client's zmq channels, and shuts
436
439
down the kernel.
437
440
"""
438
- reset_kc = kwargs .pop ('reset_kc ' , False )
441
+ cleanup_kc = kwargs .pop ('cleanup_kc ' , True )
439
442
if self .km is None :
440
443
self .start_kernel_manager ()
441
444
@@ -444,10 +447,10 @@ async def async_setup_kernel(self, **kwargs):
444
447
try :
445
448
yield
446
449
finally :
447
- if reset_kc :
450
+ if cleanup_kc :
448
451
await self ._async_cleanup_kernel ()
449
452
450
- async def async_execute (self , ** kwargs ):
453
+ async def async_execute (self , reset_kc = False , ** kwargs ):
451
454
"""
452
455
Executes each code cell.
453
456
@@ -457,16 +460,15 @@ async def async_execute(self, **kwargs):
457
460
Any option for `self.kernel_manager_class.start_kernel()`. Because
458
461
that defaults to AsyncKernelManager, this will likely include options
459
462
accepted by `AsyncKernelManager.start_kernel()``, which includes `cwd`.
460
- If present, `reset_kc` is passed to `self.async_setup_kernel`:
461
- if True, the kernel client will be reset and a new one will be created
462
- and cleaned up after execution (default: False).
463
+
464
+ `reset_kc` if True, the kernel client will be reset and a new one
465
+ will be created (default: False).
463
466
464
467
Returns
465
468
-------
466
469
nb : NotebookNode
467
470
The executed notebook.
468
471
"""
469
- reset_kc = kwargs .get ('reset_kc' , False )
470
472
if reset_kc and self .km :
471
473
await self ._async_cleanup_kernel ()
472
474
self .reset_execution_trackers ()
0 commit comments