Issue
Papermill throws exception if I need to finish the code earlier. For example with quit():
nbclient.exceptions.DeadKernelError: Kernel died
I would like to know if there is a way to instruct the code exit without papermill throwing the exception.
Example:
# check conditions if all met then run full notebook
# if not, then just finish
condition1=True
if condition1:
quit() # if condition is not met then finish here
print('continue the logic')
Solution
You can use sys.exit()
, or equivalently raise SystemExit
, as indicated here. This works because the argument to sys.exit()
has a default value of 0, meaning "successful termination". See the docs:
The optional argument arg can be an integer giving the exit status (defaulting to zero), or another type of object. If it is an integer, zero is considered “successful termination” and any nonzero value is considered “abnormal termination” by shells and the like.
Note: it used to be that using sys.exit()
would stop papermill
, but an issue was raised and fixed.
Answered By - Moot
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.