Handling the Runtime error cause by Cell execution Time out inside a python program (python 2.7)

419 views
Skip to first unread message

Sreehari S

unread,
Oct 14, 2016, 6:30:03 AM10/14/16
to Project Jupyter
Hello! 

I was working on writing a script that can test ipython notebooks.

I need to catch the Error that is raised when a cell execution times out and continue executing the remaining cells. For python 3+, I can simply do this as:

except TimeoutError as e:

But in python 2.6/2.7, a RuntimeError results (as documented here : https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/execute.py#L48 )

How do I handle this? 

In other words, when I see something like
RuntimeError: Cell execution timed out, see log for details.

I should be able to continue executing the cells following the cell causing the timeout.  (I've tried using allow_errrors = True, but that doesn't seem to help) 

Any ideas on how I can do this? 

Thank you

Thomas Kluyver

unread,
Oct 14, 2016, 9:26:46 AM10/14/16
to Project Jupyter
On 14 October 2016 at 11:30, Sreehari S <sree...@gmail.com> wrote:
But in python 2.6/2.7, a RuntimeError results (as documented here : https://github.com/jupyter/nbconvert/blob/master/nbconvert/preprocessors/execute.py#L48 )

How do I handle this? 

Catch RuntimeError?

You can also set no timeout if that's what you want, but then a cell that runs forever will keep running.

Sreehari S

unread,
Oct 14, 2016, 11:10:58 AM10/14/16
to Project Jupyter
Just got this to work! 

What I was looking for was a way to differentiate this one particular Runtime errors from the other runtime errors:

except RuntimeError as e:
                if "Cell execution timed out" in e.message:
                    print(e)
                else:
                    raise e


The above snippet seems to do the job. 

Thank you
Reply all
Reply to author
Forward
0 new messages