@@ -298,13 +298,11 @@ def __init__(self, nb, km=None, **kw):
298
298
super ().__init__ (** kw )
299
299
self .nb = nb
300
300
self .km = km
301
- self .reset_execution_trackers (reset_kc = True )
301
+ self .reset_execution_trackers ()
302
302
303
- def reset_execution_trackers (self , reset_kc = False ):
303
+ def reset_execution_trackers (self ):
304
304
"""Resets any per-execution trackers.
305
305
"""
306
- if reset_kc :
307
- self .kc = None
308
306
self .code_cells_executed = 0
309
307
self ._display_id_map = {}
310
308
self .widget_state = {}
@@ -418,6 +416,7 @@ async def async_setup_kernel(self, **kwargs):
418
416
When control returns from the yield it stops the client's zmq channels, and shuts
419
417
down the kernel.
420
418
"""
419
+ reset_kc = kwargs .pop ('reset_kc' , False )
421
420
if self .km is None :
422
421
self .start_kernel_manager ()
423
422
@@ -426,7 +425,8 @@ async def async_setup_kernel(self, **kwargs):
426
425
try :
427
426
yield
428
427
finally :
429
- await self ._async_cleanup_kernel ()
428
+ if reset_kc :
429
+ await self ._async_cleanup_kernel ()
430
430
431
431
async def async_execute (self , ** kwargs ):
432
432
"""
@@ -438,17 +438,19 @@ async def async_execute(self, **kwargs):
438
438
Any option for `self.kernel_manager_class.start_kernel()`. Because
439
439
that defaults to AsyncKernelManager, this will likely include options
440
440
accepted by `AsyncKernelManager.start_kernel()``, which includes `cwd`.
441
- If present, `reset_kc` is passed to `self.reset_execution_trackers `:
441
+ If present, `reset_kc` is passed to `self.async_setup_kernel `:
442
442
if True, the kernel client will be reset and a new one will be created
443
- (default: False).
443
+ and cleaned up after execution (default: False).
444
444
445
445
Returns
446
446
-------
447
447
nb : NotebookNode
448
448
The executed notebook.
449
449
"""
450
- reset_kc = kwargs .pop ('reset_kc' , False )
451
- self .reset_execution_trackers (reset_kc = reset_kc )
450
+ reset_kc = kwargs .get ('reset_kc' , False )
451
+ if reset_kc :
452
+ await self ._async_cleanup_kernel ()
453
+ self .reset_execution_trackers ()
452
454
453
455
async with self .async_setup_kernel (** kwargs ):
454
456
self .log .info ("Executing notebook with kernel: %s" % self .kernel_name )
0 commit comments