@@ -818,9 +818,7 @@ async def async_execute_cell(
818
818
if self .parse_md_expressions and cell .cell_type == 'markdown' :
819
819
expressions = self .parse_md_expressions (cell .source )
820
820
if expressions :
821
- if not "attachments" in cell :
822
- cell .attachments = {}
823
- cell .attachments .update (await self .async_execute_expressions (cell , cell_index , expressions ))
821
+ await self .async_execute_expressions (cell , cell_index , expressions )
824
822
825
823
if cell .cell_type != 'code' or not cell .source .strip ():
826
824
self .log .debug ("Skipping non-executing cell %s" , cell_index )
@@ -1052,20 +1050,18 @@ def handle_comm_msg(
1052
1050
self .comm_objects [comm_id ].handle_msg (msg )
1053
1051
1054
1052
async def async_execute_expressions (self , cell , cell_index : int , expressions : t .List [str ]) -> t .Dict [str , Any ]:
1055
- user_expressions = {f"md-expr-{ i } " : expr for i , expr in enumerate (expressions )}
1056
- print (user_expressions )
1057
1053
parent_msg_id = await ensure_async (
1058
1054
self .kc .execute (
1059
1055
'' ,
1060
- silent = False ,
1061
- user_expressions = user_expressions ,
1056
+ silent = True ,
1057
+ user_expressions = { f"md-expr- { i } " : expr for i , expr in enumerate ( expressions )} ,
1062
1058
)
1063
1059
)
1064
1060
task_poll_kernel_alive = asyncio .ensure_future (
1065
1061
self ._async_poll_kernel_alive ()
1066
1062
)
1067
1063
task_poll_expr_msg = asyncio .ensure_future (
1068
- self ._async_poll_expr_msg (parent_msg_id , cell , cell_index )
1064
+ self ._async_poll_expr_msg (parent_msg_id )
1069
1065
)
1070
1066
exec_timeout = None
1071
1067
self .task_poll_for_reply = asyncio .ensure_future (
@@ -1087,6 +1083,11 @@ async def async_execute_expressions(self, cell, cell_index: int, expressions: t.
1087
1083
task_poll_expr_msg .cancel ()
1088
1084
finally :
1089
1085
raise
1086
+ self ._check_raise_for_error (cell , exec_reply )
1087
+ attachments = {key : val ["data" ] for key , val in exec_reply ["content" ]["user_expressions" ].items ()}
1088
+ cell .setdefault ("attachments" , {}).update (attachments )
1089
+ self .nb ['cells' ][cell_index ] = cell
1090
+ return cell
1090
1091
1091
1092
async def _async_poll_for_expr_reply (
1092
1093
self ,
@@ -1129,24 +1130,17 @@ async def _async_poll_for_expr_reply(
1129
1130
1130
1131
async def _async_poll_expr_msg (
1131
1132
self ,
1132
- parent_msg_id : str ,
1133
- cell : NotebookNode ,
1134
- cell_index : int ) -> None :
1133
+ parent_msg_id : str ) -> None :
1135
1134
1136
1135
assert self .kc is not None
1137
1136
while True :
1138
1137
msg = await ensure_async (self .kc .iopub_channel .get_msg (timeout = None ))
1139
1138
if msg ['parent_header' ].get ('msg_id' ) == parent_msg_id :
1140
1139
try :
1141
- # Will raise CellExecutionComplete when completed
1142
- # self.process_message(msg, cell, cell_index)
1143
- print (msg )
1144
1140
msg_type = msg ['msg_type' ]
1145
1141
if msg_type == 'status' :
1146
1142
if msg ['content' ]['execution_state' ] == 'idle' :
1147
1143
raise CellExecutionComplete ()
1148
- # elif msg_type != 'execute_input':
1149
- # raise ValueError(msg)
1150
1144
except CellExecutionComplete :
1151
1145
return
1152
1146
0 commit comments