Debugging in JupyterLab

🇪🇺 🐍 EuroSciPy 2019 🐍 🇪🇺


Jeremy Tuloup - github.com/jtpio



1. Current tools for debugging Jupyter Notebooks


In [ ]:
for i in range(10):
    j = i ** 2
    print("j =", j)

ipdb


In [ ]:
for i in range(5):
    j = i ** 2
    breakpoint()  # Python 3.7+
    # import ipdb; ipdb.set_trace()
    print(j)

PixieDebugger


In [ ]:
from IPython.display import YouTubeVideo

YouTubeVideo("Z-tPeEkVqjk", start=39, width=800, height=500)

PyCharm, Visual Studio and other IDEs

Visual Studio Code Cell Debugging

From https://twitter.com/davorabbit/status/1149062343231455238


In [ ]:
from IPython.display import Video

Video("./img/vscode-cell-debugging.mp4")

2. Native debugging support for Jupyter Kernels


In [ ]:
x = 1

New debug_request, debug_reply and debug_event messages

https://jupyter-client.readthedocs.io/en/latest/messaging.html#debug-request

Debug Protocol

- Standing on the shoulder of giants

- Debug Adapter Protocol: https://microsoft.github.io/debug-adapter-protocol/specification (used in VS Code)

- ptvsd (Python Tools for Visual Studio debug server)

3. Debugger extension for JupyterLab

Prototype

Switching to xpython


In [ ]:
for i in range(5):
    j = i + 1
    k = j ** 2
    print(j, k)

In [ ]:
from ipywidgets import IntSlider

N = 5
slider = IntSlider(max=N)
slider

In [ ]:
for i in range(N + 1):
    slider.value = i
    print(i)

Thanks!