Skip to content

Commit

Permalink
Merge pull request #959 from dwjbosman/dwjbosman-patch-1
Browse files Browse the repository at this point in the history
Solves hanging indefinitely when kernel dies
  • Loading branch information
MSeal authored Mar 23, 2019
2 parents 12e148f + caeab80 commit 6cbc541
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion nbconvert/preprocessors/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,25 @@ def _wait_for_reply(self, msg_id, cell=None):

if not timeout or timeout < 0:
timeout = None
msg = self.kc.shell_channel.get_msg(timeout=timeout)

if timeout is not None:
# timeout specified
msg = self.kc.shell_channel.get_msg(timeout=timeout)
else:
#no timeout specified, if kernel dies still handle this correctly
while True:
try:
#check every few seconds if kernel is still alive
msg = self.kc.shell_channel.get_msg(timeout=5)
except Empty:
#received no message, check if kernel is still alive
if not self.kc.is_alive():
raise RuntimeError("Kernel died")

#kernel still alive, wait for a message
continue
#message received
break
except Empty:
self.log.error(
"Timeout waiting for execute reply (%is)." % self.timeout)
Expand Down

0 comments on commit 6cbc541

Please sign in to comment.