From 9853ad80d79a95d36de1e0e2a58cd2644f07c4d0 2014-02-08 00:51:10 From: MinRK Date: 2014-02-08 00:51:10 Subject: [PATCH] catch errors at a lower level in interact for cleaner tracebacks in the interact callback than the fallback case --- diff --git a/IPython/html/widgets/interaction.py b/IPython/html/widgets/interaction.py index 6c9a811..22a0ae4 100644 --- a/IPython/html/widgets/interaction.py +++ b/IPython/html/widgets/interaction.py @@ -20,6 +20,7 @@ except ImportError: from IPython.utils.signatures import signature, Parameter from inspect import getcallargs +from IPython.core.getipython import get_ipython from IPython.html.widgets import (Widget, TextWidget, FloatSliderWidget, IntSliderWidget, CheckboxWidget, DropdownWidget, ContainerWidget, DOMWidget) @@ -205,7 +206,14 @@ def interactive(__interact_f, **kwargs): container.kwargs[widget.description] = value if co: clear_output(wait=True) - container.result = f(**container.kwargs) + try: + container.result = f(**container.kwargs) + except Exception as e: + ip = get_ipython() + if ip is None: + container.log.warn("Exception in interact callback: %s", e, exc_info=True) + else: + ip.showtraceback() # Wire up the widgets for widget in kwargs_widgets: