@@ -308,6 +308,10 @@ def __init__(self, nb, km=None, **kw):
308
308
'jupyter.widget' : self .on_comm_open_jupyter_widget
309
309
}
310
310
311
+ def _update_state (self , new_state ):
312
+ self .state = new_state
313
+ self .state_history .append ([new_state , timestamp ()])
314
+
311
315
def reset_execution_trackers (self ):
312
316
"""Resets any per-execution trackers.
313
317
"""
@@ -321,6 +325,7 @@ def reset_execution_trackers(self):
321
325
# our front-end mimicing Output widgets
322
326
self .comm_objects = {}
323
327
self .state = ExecutionState .NOTHING
328
+ self .state_history = []
324
329
self .current_cell = None
325
330
self .current_cell_index = - 1
326
331
@@ -345,7 +350,7 @@ def start_kernel_manager(self):
345
350
return self .km
346
351
347
352
async def _async_cleanup_kernel (self ):
348
- self .state = ExecutionState .CLEANING_UP
353
+ self ._update_state ( ExecutionState .CLEANING_UP )
349
354
now = self .shutdown_kernel == "immediate"
350
355
try :
351
356
# Queue the manager to kill the process, and recover gracefully if it's already dead.
@@ -382,7 +387,7 @@ async def async_start_new_kernel_client(self, **kwargs):
382
387
The id of the started kernel.
383
388
"""
384
389
385
- self .state = ExecutionState .STARTING_KERNEL_CLIENT
390
+ self ._update_state ( ExecutionState .STARTING_KERNEL_CLIENT )
386
391
resource_path = self .resources .get ('metadata' , {}).get ('path' ) or None
387
392
if resource_path and 'cwd' not in kwargs :
388
393
kwargs ["cwd" ] = resource_path
@@ -515,10 +520,10 @@ async def async_execute(self, reset_kc=False, **kwargs):
515
520
if reset_kc and self .km :
516
521
await self ._async_cleanup_kernel ()
517
522
self .reset_execution_trackers ()
518
- self .state = ExecutionState .STARTUP
523
+ self ._update_state ( ExecutionState .STARTUP )
519
524
520
525
async with self .async_setup_kernel (** kwargs ):
521
- self .state = ExecutionState .EXECUTING
526
+ self ._update_state ( ExecutionState .EXECUTING )
522
527
self .log .info ("Executing notebook with kernel: %s" % self .kernel_name )
523
528
for index , cell in enumerate (self .nb .cells ):
524
529
# Ignore `'execution_count' in content` as it's always 1
@@ -530,7 +535,7 @@ async def async_execute(self, reset_kc=False, **kwargs):
530
535
info_msg = await self .async_wait_for_reply (msg_id )
531
536
self .nb .metadata ['language_info' ] = info_msg ['content' ]['language_info' ]
532
537
self .set_widgets_metadata ()
533
- self .state = ExecutionState .COMPLETE
538
+ self ._update_state ( ExecutionState .COMPLETE )
534
539
return self .nb
535
540
536
541
execute = run_sync (async_execute )
0 commit comments