@@ -96,7 +96,8 @@ class NotebookExecutionManager:
9696 COMPLETED = "completed"
9797 FAILED = "failed"
9898
99- def __init__ (self , nb , output_path = None , log_output = False , progress_bar = True , autosave_cell_every = 30 ):
99+ def __init__ (self , nb , output_path = None , log_output = False , progress_bar = True , autosave_cell_every = 30 ,
100+ live_display = None ):
100101 self .nb = nb
101102 self .output_path = output_path
102103 self .log_output = log_output
@@ -105,6 +106,7 @@ def __init__(self, nb, output_path=None, log_output=False, progress_bar=True, au
105106 self .autosave_cell_every = autosave_cell_every
106107 self .max_autosave_pct = 25
107108 self .last_save_time = self .now () # Not exactly true, but simplifies testing logic
109+ self .live_display = live_display # optional LiveTreeDisplay — replaces tqdm when set
108110 self .pbar = None
109111 if progress_bar :
110112 # lazy import due to implicit slow ipython import
@@ -227,10 +229,14 @@ def cell_start(self, cell, cell_index=None, **kwargs):
227229 cell .metadata .papermill ["status" ] = self .RUNNING
228230 cell .metadata .papermill ['exception' ] = False
229231
230- # injects optional description of the current cell directly in the tqdm
231- cell_description = self .get_cell_description (cell )
232- if cell_description is not None and hasattr (self , 'pbar' ) and self .pbar :
233- self .pbar .set_description (f"Executing { cell_description } " )
232+ if self .live_display is not None :
233+ if cell_index is not None :
234+ self .live_display .on_cell_start (cell_index )
235+ else :
236+ # injects optional description of the current cell directly in the tqdm
237+ cell_description = self .get_cell_description (cell )
238+ if cell_description is not None and hasattr (self , 'pbar' ) and self .pbar :
239+ self .pbar .set_description (f"Executing { cell_description } " )
234240
235241 self .save ()
236242
@@ -246,6 +252,8 @@ def cell_exception(self, cell, cell_index=None, **kwargs):
246252 cell .metadata .papermill ['exception' ] = True
247253 cell .metadata .papermill ['status' ] = self .FAILED
248254 self .nb .metadata .papermill ['exception' ] = True
255+ if self .live_display is not None and cell_index is not None :
256+ self .live_display .on_cell_exception (cell_index )
249257
250258 @catch_nb_assignment
251259 def cell_complete (self , cell , cell_index = None , ** kwargs ):
@@ -272,7 +280,10 @@ def cell_complete(self, cell, cell_index=None, **kwargs):
272280 cell .metadata .papermill ['status' ] = self .COMPLETED
273281
274282 self .save ()
275- if self .pbar :
283+ if self .live_display is not None :
284+ if cell_index is not None :
285+ self .live_display .on_cell_complete (self .nb .cells [cell_index ], cell_index )
286+ elif self .pbar :
276287 self .pbar .update (1 )
277288
278289 @catch_nb_assignment
@@ -348,6 +359,7 @@ def execute_notebook(
348359 progress_bar = True ,
349360 log_output = False ,
350361 autosave_cell_every = 30 ,
362+ live_display = None ,
351363 ** kwargs ,
352364 ):
353365 """
@@ -364,6 +376,7 @@ def execute_notebook(
364376 progress_bar = progress_bar ,
365377 log_output = log_output ,
366378 autosave_cell_every = autosave_cell_every ,
379+ live_display = live_display ,
367380 )
368381
369382 nb_man .notebook_start ()
0 commit comments