Skip to content

Commit 5a2f861

Browse files
author
Golf Player
committed
Add timestamps for every history update
1 parent 0e122bb commit 5a2f861

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

nbclient/client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ def __init__(self, nb, km=None, **kw):
308308
'jupyter.widget': self.on_comm_open_jupyter_widget
309309
}
310310

311+
def _update_state(self, new_state):
312+
self.state = new_state
313+
self.state_history.append([new_state, timestamp()])
314+
311315
def reset_execution_trackers(self):
312316
"""Resets any per-execution trackers.
313317
"""
@@ -321,6 +325,7 @@ def reset_execution_trackers(self):
321325
# our front-end mimicing Output widgets
322326
self.comm_objects = {}
323327
self.state = ExecutionState.NOTHING
328+
self.state_history = []
324329
self.current_cell = None
325330
self.current_cell_index = -1
326331

@@ -345,7 +350,7 @@ def start_kernel_manager(self):
345350
return self.km
346351

347352
async def _async_cleanup_kernel(self):
348-
self.state = ExecutionState.CLEANING_UP
353+
self._update_state(ExecutionState.CLEANING_UP)
349354
now = self.shutdown_kernel == "immediate"
350355
try:
351356
# 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):
382387
The id of the started kernel.
383388
"""
384389

385-
self.state = ExecutionState.STARTING_KERNEL_CLIENT
390+
self._update_state(ExecutionState.STARTING_KERNEL_CLIENT)
386391
resource_path = self.resources.get('metadata', {}).get('path') or None
387392
if resource_path and 'cwd' not in kwargs:
388393
kwargs["cwd"] = resource_path
@@ -515,10 +520,10 @@ async def async_execute(self, reset_kc=False, **kwargs):
515520
if reset_kc and self.km:
516521
await self._async_cleanup_kernel()
517522
self.reset_execution_trackers()
518-
self.state = ExecutionState.STARTUP
523+
self._update_state(ExecutionState.STARTUP)
519524

520525
async with self.async_setup_kernel(**kwargs):
521-
self.state = ExecutionState.EXECUTING
526+
self._update_state(ExecutionState.EXECUTING)
522527
self.log.info("Executing notebook with kernel: %s" % self.kernel_name)
523528
for index, cell in enumerate(self.nb.cells):
524529
# Ignore `'execution_count' in content` as it's always 1
@@ -530,7 +535,7 @@ async def async_execute(self, reset_kc=False, **kwargs):
530535
info_msg = await self.async_wait_for_reply(msg_id)
531536
self.nb.metadata['language_info'] = info_msg['content']['language_info']
532537
self.set_widgets_metadata()
533-
self.state = ExecutionState.COMPLETE
538+
self._update_state(ExecutionState.COMPLETE)
534539
return self.nb
535540

536541
execute = run_sync(async_execute)

0 commit comments

Comments
 (0)