Skip to content

Commit

Permalink
Add validation for timeout to ensure a positive value
Browse files Browse the repository at this point in the history
  • Loading branch information
tmetzl authored and brichet committed Mar 23, 2023
1 parent 71108d6 commit 4d14ce6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions nbgrader/preprocessors/execute.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from nbconvert.preprocessors import ExecutePreprocessor, CellExecutionError
from traitlets import Bool, List, Integer
from traitlets import Bool, List, Integer, validate, TraitError
from textwrap import dedent

from . import NbGraderPreprocessor
Expand Down Expand Up @@ -57,7 +57,6 @@ class Execute(NbGraderPreprocessor, ExecutePreprocessor):

timeout = Integer(
30,
allow_none=True,
help=dedent(
"""
The time to wait (in seconds) for output from executions.
Expand Down Expand Up @@ -90,6 +89,13 @@ class Execute(NbGraderPreprocessor, ExecutePreprocessor):
""")
).tag(config=True)

@validate('timeout')
def _validate_timeout(self, proposal):
value = int(proposal['value'])
if value <= 0:
raise TraitError("the timeout should be a positive value")
return value

def on_cell_executed(self, **kwargs):
cell = kwargs['cell']
reply = kwargs['execute_reply']
Expand Down

0 comments on commit 4d14ce6

Please sign in to comment.