Skip to content

Commit 81a1071

Browse files
author
Doug Blank
committed
Detect error on output
1 parent 8e8a96d commit 81a1071

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

jupyter_client/runapp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,17 @@ def start(self):
108108
self.log.debug("jupyter run: executing `%s`" % filename)
109109
with open(filename) as fp:
110110
cell = fp.read()
111-
self.run_cell(cell)
111+
return_code = self.run_cell(cell)
112+
if return_code:
113+
raise Exception("jupyter-run error running '%s'" % filename)
112114

113115
def run_cell(self, cell):
114116
"""
115117
Run a cell on a KernelClient
116118
Any output from the cell will be displayed.
117119
"""
118120
msg_id = self.kernel_client.execute(cell)
121+
return_code = 0
119122
while True:
120123
try:
121124
msg = self.kernel_client.get_iopub_msg(timeout=OUTPUT_TIMEOUT)
@@ -133,13 +136,18 @@ def run_cell(self, cell):
133136
elif msg_type == 'stream':
134137
stream = getattr(sys, content['name'])
135138
stream.write(content['text'])
139+
# TODO: remove this when all kernels use error msg_type:
140+
if content['name'] == "stderr":
141+
return_code = 1
136142
elif msg_type in ('display_data', 'execute_result', 'error'):
137143
if msg_type == 'error':
138144
print('\n'.join(content['traceback']), file=sys.stderr)
145+
return_code = 1
139146
else:
140147
sys.stdout.write(content['data'].get('text/plain', ''))
141148
else:
142149
pass
150+
return return_code
143151

144152
main = launch_new_instance = RunApp.launch_instance
145153

0 commit comments

Comments
 (0)