mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-04-20 01:30:58 +01:00
Don't break prematurely when running a cell on an ipython kernel
The kernel may go idle before it processes the next input, which break the while=True loop in run_cell() early. Wait for an acknowledgement of the input we've sent to the kernel before considering an idle message to mean that the cell has been parsed.
This commit is contained in:
parent
0faa5ae455
commit
2b04cb38d9
@ -52,6 +52,7 @@ def run_cell(kernel_client, cell):
|
|||||||
"""Run a cell of a notebook in an ipython kernel and return its output"""
|
"""Run a cell of a notebook in an ipython kernel and return its output"""
|
||||||
kernel_client.execute(cell.input)
|
kernel_client.execute(cell.input)
|
||||||
|
|
||||||
|
input_acknowledged = False
|
||||||
outs = []
|
outs = []
|
||||||
while True:
|
while True:
|
||||||
msg = kernel_client.get_iopub_msg()
|
msg = kernel_client.get_iopub_msg()
|
||||||
@ -61,11 +62,12 @@ def run_cell(kernel_client, cell):
|
|||||||
out = NotebookNode(output_type=msg_type)
|
out = NotebookNode(output_type=msg_type)
|
||||||
|
|
||||||
if msg_type == "status":
|
if msg_type == "status":
|
||||||
if content["execution_state"] == "idle":
|
if content["execution_state"] == "idle" and input_acknowledged:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
elif msg_type == "pyin":
|
elif msg_type == "pyin":
|
||||||
|
input_acknowledged = True
|
||||||
continue
|
continue
|
||||||
elif msg_type == "stream":
|
elif msg_type == "stream":
|
||||||
out.stream = content["name"]
|
out.stream = content["name"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user