Skip to content

Commit

Permalink
make nbconvert 5.5 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Feb 5, 2020
1 parent 17d4798 commit 0ac7d3a
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions voila/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

from ipykernel.jsonutil import json_clean

try:
TimeoutError # Py 3
except NameError:
TimeoutError = RuntimeError # Py 2


def strip_code_cell_errors(cell):
"""Strip any error outputs and traceback from a code cell."""
Expand Down Expand Up @@ -231,6 +236,28 @@ def clear_output(self, outs, msg, cell_index):
return
super(VoilaExecutePreprocessor, self).clear_output(outs, msg, cell_index)

# make it nbconvert 5.5 compatible
def _get_timeout(self, cell):
if self.timeout_func is not None and cell is not None:
timeout = self.timeout_func(cell)
else:
timeout = self.timeout

if not timeout or timeout < 0:
timeout = None

return timeout

# make it nbconvert 5.5 compatible
def _handle_timeout(self, timeout):
self.log.error(
"Timeout waiting for execute reply (%is)." % timeout)
if self.interrupt_on_timeout:
self.log.error("Interrupting kernel")
self.km.interrupt_kernel()
else:
raise TimeoutError("Cell execution timed out")

def run_cell(self, cell, cell_index=0, store_history=False):
parent_msg_id = self.kc.execute(cell.source, store_history=store_history, stop_on_error=not self.allow_errors)
self.log.debug("Executing cell:\n%s", cell.source)
Expand Down Expand Up @@ -260,7 +287,7 @@ def run_cell(self, cell, cell_index=0, store_history=False):
if not rlist and not wlist and not xlist:
self._check_alive()
if monotonic() > deadline:
self._handle_timeout(exec_timeout, cell)
self._handle_timeout(exec_timeout)
if xlist:
raise RuntimeError("Oops, unexpected rror")
if self.kc.shell_channel.socket in rlist:
Expand All @@ -277,7 +304,7 @@ def run_cell(self, cell, cell_index=0, store_history=False):
else:
self.log.debug("Received message for which we were not the parent: %s", msg)
else:
self._handle_timeout(exec_timeout, cell)
self._handle_timeout(exec_timeout)
break

return execute_reply, cell.outputs
Expand Down

0 comments on commit 0ac7d3a

Please sign in to comment.