Callback exceptions on jupyter

I guess I am missing something obvious here… but, is it possible to display callback exceptions on jupyter?

E.g. using the following, arguably, contrived example:

  1. If there are no exceptions, everything works as expected. I.e. you get a Dynamic Map which gets updated as you move the mouse.
  2. If there is an exception in the if branch you get a traceback and, obviously, the DynamicMap never gets created.
  3. If there is an exception in the else branch, then the “initial” DynamicMap gets created, but it, obviously never gets updated when you move the mouse and, more importantly, the traceback gets lost which means you can’t “easily” figure out what is the problem. Furthremore, as pointed out by @jazz here the print() function doesn’t print anything and breakpoint is ignored.
import holoviews as hv
import panel as pn

def callback(x, y):
    if x is None or y is None:
        # 1/0
        return hv.Points([]).opts(title="No points yet")
    else:
        # 1/0
        return hv.Points([(x, y)]).opts(title="%.3f - %.3f" % (x, y))
    
pointer = hv.streams.PointerXY()
dmap = hv.DynamicMap(callback, streams=[pointer])

pn.Row(dmap).servable()

if you run the same example with panel serve then the traceback gets printed on the console without any issue. Is it possible to get the same traceback on jupyter, too?

2 Likes

Yes, that definitely makes it more painful to debug callbacks. I don’t know of a solution, though!

I opened a feature-request ticket on github: Make debugging callbacks on jupyter easier · Issue #5424 · holoviz/holoviews · GitHub

I came here looking for answers to the same question. What I was able to do was write to a file from inside the callback. Slightly more tedious than prints, but gets the job done just the same.

I also did that, but the real point is why does the exception get lost? What happens to stdout/stderr? Where are they getting redirected to?

I added on the ticket a workaround for sending desktop notifications with the traceback.