@@ -802,9 +802,7 @@ async def async_execute_cell(
802
802
if self .parse_md_expressions and cell .cell_type == 'markdown' :
803
803
expressions = self .parse_md_expressions (cell .source )
804
804
if expressions :
805
- if not "attachments" in cell :
806
- cell .attachments = {}
807
- cell .attachments .update (await self .async_execute_expressions (cell , cell_index , expressions ))
805
+ await self .async_execute_expressions (cell , cell_index , expressions )
808
806
809
807
if cell .cell_type != 'code' or not cell .source .strip ():
810
808
self .log .debug ("Skipping non-executing cell %s" , cell_index )
@@ -1028,20 +1026,18 @@ def handle_comm_msg(self, outs: t.List, msg: t.Dict, cell_index: int) -> None:
1028
1026
self .comm_objects [comm_id ].handle_msg (msg )
1029
1027
1030
1028
async def async_execute_expressions (self , cell , cell_index : int , expressions : t .List [str ]) -> t .Dict [str , Any ]:
1031
- user_expressions = {f"md-expr-{ i } " : expr for i , expr in enumerate (expressions )}
1032
- print (user_expressions )
1033
1029
parent_msg_id = await ensure_async (
1034
1030
self .kc .execute (
1035
1031
'' ,
1036
- silent = False ,
1037
- user_expressions = user_expressions ,
1032
+ silent = True ,
1033
+ user_expressions = { f"md-expr- { i } " : expr for i , expr in enumerate ( expressions )} ,
1038
1034
)
1039
1035
)
1040
1036
task_poll_kernel_alive = asyncio .ensure_future (
1041
1037
self ._async_poll_kernel_alive ()
1042
1038
)
1043
1039
task_poll_expr_msg = asyncio .ensure_future (
1044
- self ._async_poll_expr_msg (parent_msg_id , cell , cell_index )
1040
+ self ._async_poll_expr_msg (parent_msg_id )
1045
1041
)
1046
1042
exec_timeout = None
1047
1043
self .task_poll_for_reply = asyncio .ensure_future (
@@ -1063,6 +1059,11 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
1063
1059
task_poll_expr_msg .cancel ()
1064
1060
finally :
1065
1061
raise
1062
+ self ._check_raise_for_error (cell , exec_reply )
1063
+ attachments = {key : val ["data" ] for key , val in exec_reply ["content" ]["user_expressions" ].items ()}
1064
+ cell .setdefault ("attachments" , {}).update (attachments )
1065
+ self .nb ['cells' ][cell_index ] = cell
1066
+ return cell
1066
1067
1067
1068
async def _async_poll_for_expr_reply (
1068
1069
self ,
@@ -1105,24 +1106,17 @@ async def _async_poll_for_expr_reply(
1105
1106
1106
1107
async def _async_poll_expr_msg (
1107
1108
self ,
1108
- parent_msg_id : str ,
1109
- cell : NotebookNode ,
1110
- cell_index : int ) -> None :
1109
+ parent_msg_id : str ) -> None :
1111
1110
1112
1111
assert self .kc is not None
1113
1112
while True :
1114
1113
msg = await ensure_async (self .kc .iopub_channel .get_msg (timeout = None ))
1115
1114
if msg ['parent_header' ].get ('msg_id' ) == parent_msg_id :
1116
1115
try :
1117
- # Will raise CellExecutionComplete when completed
1118
- # self.process_message(msg, cell, cell_index)
1119
- print (msg )
1120
1116
msg_type = msg ['msg_type' ]
1121
1117
if msg_type == 'status' :
1122
1118
if msg ['content' ]['execution_state' ] == 'idle' :
1123
1119
raise CellExecutionComplete ()
1124
- # elif msg_type != 'execute_input':
1125
- # raise ValueError(msg)
1126
1120
except CellExecutionComplete :
1127
1121
return
1128
1122
0 commit comments