-
Notifications
You must be signed in to change notification settings - Fork 963
Description
ipywidgets.Output() context manager supresses exceptions and prevents correct exit code
Description
For example take this code snippet and save it to a cell of a *.ipynb notebook.
import ipywidgets
o = ipywidgets.Output()
with o:
raise Exception()
display(o)
print("execution continues")Then execute the notebook with ipython:
$ ipython path/to/notebook.ipynb
The output will be
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
/tmp/ipywidgets_bug/example.ipynb in <module>
2 o = ipywidgets.Output()
3 with o:
----> 4 raise Exception()
5 display(o)
6 print("execution continues")
Exception:
Output()
execution continues
Expected behavior
The call to ipython should fail. If it is not aborted at the time when the exception is raised, at least it should exit with exit code other than 0.
Actual Behavior
The exception raised in the output context is suppressed. Execution continues and the ipython call exits with code 0.
Also the stderr output from the exception is not displayed unless display(o) is called explicitly.
But this I reckon is expected behavior.
Context
- ipywidgets version
8.0.0a4 - Operating System and version:
archlinux kernel 5.12.7-arch1-1 - Browser and version:
not used
Troubleshoot Output
$PATH: /tmp/ipywidgets_bug/.venv/bin /usr/local/bin /usr/bin /usr/local/sbin /opt/cuda/bin /opt/cuda/nsight_compute /opt/cuda/nsight_systems/bin /usr/lib/jvm/default/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perlsys.path:
/tmp/ipywidgets_bug/.venv/bin
/usr/lib/python39.zip
/usr/lib/python3.9
/usr/lib/python3.9/lib-dynload
/tmp/ipywidgets_bug/.venv/lib/python3.9/site-packagessys.executable:
/tmp/ipywidgets_bug/.venv/bin/pythonsys.version:
3.9.5 (default, May 24 2021, 12:50:35)
[GCC 11.1.0]platform.platform():
Linux-5.12.7-arch1-1-x86_64-with-glibc2.33which -a jupyter:
/tmp/ipywidgets_bug/.venv/bin/jupyter
/usr/bin/jupyterpip list:
Package Version
------------------ -------
attrs 21.2.0
backcall 0.2.0
decorator 5.0.9
ipykernel 5.5.5
ipython 7.24.1
ipython-genutils 0.2.0
ipywidgets 8.0.0a4
jedi 0.18.0
jsonschema 3.2.0
jupyter-client 6.1.12
jupyter-core 4.7.1
jupyterlab-widgets 2.0.0a1
matplotlib-inline 0.1.2
nbformat 5.1.3
parso 0.8.2
pexpect 4.8.0
pickleshare 0.7.5
pip 21.1.1
prompt-toolkit 3.0.18
ptyprocess 0.7.0
Pygments 2.9.0
pyrsistent 0.17.3
python-dateutil 2.8.1
pyzmq 22.1.0
setuptools 56.0.0
six 1.16.0
tornado 6.1
traitlets 5.0.5
wcwidth 0.2.5
widgetsnbextension 4.0.0a2
Command Line Output
[TerminalIPythonApp] IPYTHONDIR set to: /home/XXXX/.ipython [TerminalIPythonApp] Using existing profile dir: '/home/XXXX/.ipython/profile_default' [TerminalIPythonApp] Searching path ['/tmp/ipywidgets_bug', '/home/XXXX/.ipython/profile_default', '/tmp/ipywidgets_bug/.venv/etc/ipython', '/usr/local/etc/ipython', '/etc/ipython'] for config files [TerminalIPythonApp] Attempting to load config file: ipython_config.py [TerminalIPythonApp] Looking for ipython_config in /etc/ipython [TerminalIPythonApp] Looking for ipython_config in /usr/local/etc/ipython [TerminalIPythonApp] Looking for ipython_config in /tmp/ipywidgets_bug/.venv/etc/ipython [TerminalIPythonApp] Looking for ipython_config in /home/XXXX/.ipython/profile_default [TerminalIPythonApp] Looking for ipython_config in /tmp/ipywidgets_bug[TerminalIPythonApp] Loading IPython extensions...
[TerminalIPythonApp] Loading IPython extension: storemagic
[TerminalIPythonApp] Running file in user namespace: /tmp/ipywidgets_bug/example.ipynbException Traceback (most recent call last)
/tmp/ipywidgets_bug/example.ipynb in
2 o = ipywidgets.Output()
3 with o:
----> 4 raise Exception()
5 display(o)
6 print("execution continues")Exception:
Output()
execution continues
[TerminalIPythonApp] IPython not interactive...