@@ -278,10 +278,10 @@ def _kernel_manager_class_default(self) -> KernelManager:
278
278
)
279
279
280
280
def __init__ (
281
- self ,
282
- nb : NotebookNode ,
283
- km : t .Optional [KernelManager ] = None ,
284
- ** kw ) -> None :
281
+ self ,
282
+ nb : NotebookNode ,
283
+ km : t .Optional [KernelManager ] = None ,
284
+ ** kw ) -> None :
285
285
"""Initializes the execution manager.
286
286
287
287
Parameters
@@ -489,9 +489,9 @@ def on_signal():
489
489
pass
490
490
491
491
async def async_execute (
492
- self ,
493
- reset_kc : bool = False ,
494
- ** kwargs ) -> NotebookNode :
492
+ self ,
493
+ reset_kc : bool = False ,
494
+ ** kwargs ) -> NotebookNode :
495
495
"""
496
496
Executes each code cell.
497
497
@@ -554,9 +554,9 @@ def set_widgets_metadata(self) -> None:
554
554
widget ['buffers' ] = buffers
555
555
556
556
def _update_display_id (
557
- self ,
558
- display_id : str ,
559
- msg : t .Dict ) -> None :
557
+ self ,
558
+ display_id : str ,
559
+ msg : t .Dict ) -> None :
560
560
"""Update outputs with a given display_id"""
561
561
if display_id not in self ._display_id_map :
562
562
self .log .debug ("display id %r not in %s" , display_id , self ._display_id_map )
@@ -578,14 +578,15 @@ def _update_display_id(
578
578
outputs [output_idx ]['data' ] = out ['data' ]
579
579
outputs [output_idx ]['metadata' ] = out ['metadata' ]
580
580
581
- async def _async_poll_for_reply (self ,
582
- msg_id : str ,
583
- cell : NotebookNode ,
584
- timeout : t .Optional [int ],
585
- task_poll_output_msg : asyncio .Future ) -> t .Dict :
581
+ async def _async_poll_for_reply (
582
+ self ,
583
+ msg_id : str ,
584
+ cell : NotebookNode ,
585
+ timeout : t .Optional [int ],
586
+ task_poll_output_msg : asyncio .Future ) -> t .Dict :
586
587
587
588
assert self .kc is not None
588
- new_timeout : t .Optional [float ]= None
589
+ new_timeout : t .Optional [float ] = None
589
590
if timeout is not None :
590
591
deadline = monotonic () + timeout
591
592
new_timeout = float (timeout )
@@ -615,10 +616,10 @@ async def _async_poll_for_reply(self,
615
616
await self ._async_handle_timeout (timeout , cell )
616
617
617
618
async def _async_poll_output_msg (
618
- self ,
619
- parent_msg_id : str ,
620
- cell : NotebookNode ,
621
- cell_index : int ) -> None :
619
+ self ,
620
+ parent_msg_id : str ,
621
+ cell : NotebookNode ,
622
+ cell_index : int ) -> None :
622
623
623
624
assert self .kc is not None
624
625
while True :
@@ -642,9 +643,9 @@ def _get_timeout(self, cell: t.Optional[NotebookNode]) -> int:
642
643
return timeout
643
644
644
645
async def _async_handle_timeout (
645
- self ,
646
- timeout : int ,
647
- cell : t .Optional [NotebookNode ] = None ) -> None :
646
+ self ,
647
+ timeout : int ,
648
+ cell : t .Optional [NotebookNode ] = None ) -> None :
648
649
649
650
assert self .km is not None
650
651
self .log .error ("Timeout waiting for execute reply (%is)." % timeout )
@@ -663,9 +664,9 @@ async def _async_check_alive(self) -> None:
663
664
raise DeadKernelError ("Kernel died" )
664
665
665
666
async def async_wait_for_reply (
666
- self ,
667
- msg_id : str ,
668
- cell : t .Optional [NotebookNode ] = None ) -> t .Optional [t .Dict ]:
667
+ self ,
668
+ msg_id : str ,
669
+ cell : t .Optional [NotebookNode ] = None ) -> t .Optional [t .Dict ]:
669
670
670
671
assert self .kc is not None
671
672
# wait for finish, with timeout
@@ -699,9 +700,9 @@ def _passed_deadline(self, deadline: int) -> bool:
699
700
return False
700
701
701
702
def _check_raise_for_error (
702
- self ,
703
- cell : NotebookNode ,
704
- exec_reply : t .Optional [t .Dict ]) -> None :
703
+ self ,
704
+ cell : NotebookNode ,
705
+ exec_reply : t .Optional [t .Dict ]) -> None :
705
706
706
707
cell_allows_errors = self .allow_errors or "raises-exception" in cell .metadata .get (
707
708
"tags" , []
@@ -712,11 +713,11 @@ def _check_raise_for_error(
712
713
raise CellExecutionError .from_cell_and_msg (cell , exec_reply ['content' ])
713
714
714
715
async def async_execute_cell (
715
- self ,
716
- cell : NotebookNode ,
717
- cell_index : int ,
718
- execution_count : t .Optional [int ] = None ,
719
- store_history : bool = True ) -> NotebookNode :
716
+ self ,
717
+ cell : NotebookNode ,
718
+ cell_index : int ,
719
+ execution_count : t .Optional [int ] = None ,
720
+ store_history : bool = True ) -> NotebookNode :
720
721
"""
721
722
Executes a single code cell.
722
723
@@ -798,10 +799,10 @@ async def async_execute_cell(
798
799
execute_cell = run_sync (async_execute_cell )
799
800
800
801
def process_message (
801
- self ,
802
- msg : t .Dict ,
803
- cell : NotebookNode ,
804
- cell_index : int ) -> t .Optional [t .List ]:
802
+ self ,
803
+ msg : t .Dict ,
804
+ cell : NotebookNode ,
805
+ cell_index : int ) -> t .Optional [t .List ]:
805
806
"""
806
807
Processes a kernel message, updates cell state, and returns the
807
808
resulting output object that was appended to cell.outputs.
@@ -864,11 +865,11 @@ def process_message(
864
865
return None
865
866
866
867
def output (
867
- self ,
868
- outs : t .List ,
869
- msg : t .Dict ,
870
- display_id : str ,
871
- cell_index : int ) -> t .Optional [t .List ]:
868
+ self ,
869
+ outs : t .List ,
870
+ msg : t .Dict ,
871
+ display_id : str ,
872
+ cell_index : int ) -> t .Optional [t .List ]:
872
873
873
874
msg_type = msg ['msg_type' ]
874
875
@@ -904,10 +905,10 @@ def output(
904
905
return out
905
906
906
907
def clear_output (
907
- self ,
908
- outs : t .List ,
909
- msg : t .Dict ,
910
- cell_index : int ) -> None :
908
+ self ,
909
+ outs : t .List ,
910
+ msg : t .Dict ,
911
+ cell_index : int ) -> None :
911
912
912
913
content = msg ['content' ]
913
914
@@ -928,18 +929,18 @@ def clear_output(
928
929
self .clear_display_id_mapping (cell_index )
929
930
930
931
def clear_display_id_mapping (
931
- self ,
932
- cell_index : int ) -> None :
932
+ self ,
933
+ cell_index : int ) -> None :
933
934
934
935
for display_id , cell_map in self ._display_id_map .items ():
935
936
if cell_index in cell_map :
936
937
cell_map [cell_index ] = []
937
938
938
939
def handle_comm_msg (
939
- self ,
940
- outs : t .List ,
941
- msg : t .Dict ,
942
- cell_index : int ) -> None :
940
+ self ,
941
+ outs : t .List ,
942
+ msg : t .Dict ,
943
+ cell_index : int ) -> None :
943
944
944
945
content = msg ['content' ]
945
946
data = content ['data' ]
@@ -989,9 +990,9 @@ def _get_buffer_data(self, msg: t.Dict) -> t.List[t.Dict[str, str]]:
989
990
return encoded_buffers
990
991
991
992
def register_output_hook (
992
- self ,
993
- msg_id : str ,
994
- hook : t .Callable ) -> None :
993
+ self ,
994
+ msg_id : str ,
995
+ hook : t .Callable ) -> None :
995
996
"""Registers an override object that handles output/clear_output instead.
996
997
997
998
Multiple hooks can be registered, where the last one will be used (stack based)
@@ -1001,9 +1002,9 @@ def register_output_hook(
1001
1002
self .output_hook_stack [msg_id ].append (hook )
1002
1003
1003
1004
def remove_output_hook (
1004
- self ,
1005
- msg_id : str ,
1006
- hook : t .Callable ) -> None :
1005
+ self ,
1006
+ msg_id : str ,
1007
+ hook : t .Callable ) -> None :
1007
1008
"""Unregisters an override object that handles output/clear_output instead"""
1008
1009
# mimics
1009
1010
# https://jupyterlab.github.io/jupyterlab/services/interfaces/kernel.ikernelconnection.html#removemessagehook
@@ -1023,10 +1024,10 @@ def on_comm_open_jupyter_widget(self, msg: t.Dict):
1023
1024
1024
1025
1025
1026
def execute (
1026
- nb : NotebookNode ,
1027
- cwd : t .Optional [str ] = None ,
1028
- km : t .Optional [KernelManager ] = None ,
1029
- ** kwargs ) -> NotebookClient :
1027
+ nb : NotebookNode ,
1028
+ cwd : t .Optional [str ] = None ,
1029
+ km : t .Optional [KernelManager ] = None ,
1030
+ ** kwargs ) -> NotebookClient :
1030
1031
"""Execute a notebook's code, updating outputs within the notebook object.
1031
1032
1032
1033
This is a convenient wrapper around NotebookClient. It returns the
0 commit comments