Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Visual Debugger for Jupyter Notebooks: Myth or Reality?

Visual Debugger for Jupyter Notebooks: Myth or Reality?

Many Python developers like Jupyter Notebooks for their flexibility: they are very useful for interactive prototyping, scientific experiments, visualizations and many other tasks. There are different development tools which make working with Jupyter Notebooks easier and smoother, but all of them lack very important feature: visual debugger. Since Jupyter Kernel is a usual Python process, it looks reasonably to use one of existing Python debuggers with it. But is it really possible?

In this talk we’ll try to understand how Python debugger should be changed to work with Jupyter cells and how these changes are already implemented in the PyCharm IDE. After that we’ll look into the whole Jupyter architecture and try to understand which bottlenecks in it prevent creation of universal Jupyter debugger at the moment.

This talk requires a basic knowledge of Jupyter Notebooks and understanding of Python functions and objects. It will be interesting for people who want to learn internals of the tools they use every day. Also it might be an inspiration for people who want to implement a visual debugger in their favourite IDE.

Elizaveta Shashkova

July 10, 2019
Tweet

More Decks by Elizaveta Shashkova

Other Decks in Programming

Transcript

  1. Tracing Function 11 def greet_neighbors(): planets = ["Mars", "Venus"] for

    p in planets: print(f"Hi {p}!") return len(planets) sys.settrace(tracefunc) greet_neighbors() 1 2 3 4 5 6 7 8 9
  2. Tracing Function 12 1 2 3 4 5 6 7

    8 9 1 call def greet_neighbors(): planets = ["Mars", "Venus"] for p in planets: print(f"Hi {p}!") return len(planets) sys.settrace(tracefunc) greet_neighbors()
  3. Tracing Function 13 1 2 3 4 5 6 7

    8 9 1 call 2 line def greet_neighbors(): planets = ["Mars", "Venus"] for p in planets: print(f"Hi {p}!") return len(planets) sys.settrace(tracefunc) greet_neighbors()
  4. Tracing Function 14 1 2 3 4 5 6 7

    8 9 1 call 2 line 3 line 4 line Hi Mars! def greet_neighbors(): planets = ["Mars", "Venus"] for p in planets: print(f"Hi {p}!") return len(planets) sys.settrace(tracefunc) greet_neighbors()
  5. Tracing Function 15 1 2 3 4 5 6 7

    8 9 1 call 2 line 3 line 4 line Hi Mars! 3 line 4 line Hi Venus! def greet_neighbors(): planets = ["Mars", "Venus"] for p in planets: print(f"Hi {p}!") return len(planets) sys.settrace(tracefunc) greet_neighbors()
  6. Tracing Function 16 1 2 3 4 5 6 7

    8 9 def greet_neighbors(): planets = ["Mars", "Venus"] for p in planets: print(f"Hi {p}!") return len(planets) sys.settrace(tracefunc) greet_neighbors() 1 call 2 line 3 line 4 line Hi Mars! 3 line 4 line Hi Venus! 5 line 5 return
  7. Breakpoint •frame.f_lineno - current line number •frame.f_code.co_filename - current file

    name •Equals to breakpoint’s file and line -> suspend program! 18
  8. Cells Execution •Kernel generates a unique name for each cell

    •<ipython-input-5-11faed10a894> •File name of a generated 
 code object 25 IPython kernel code execution
  9. Jupyter Breakpoints •Python files: (filename, line number) -> unique location

    •Jupyter Notebooks: •generated cell name •line inside code object 28
  10. IPython kernel IDE Source Mapping 31 ? cell source code

    MyNotebook.ipynb cell id generated <code object>
  11. Jupyter Architecture 51 •Event loop in a main thread for

    execution events •Event loop for output events
  12. Live Demo 64 •PyCharm doesn’t convert Jupyter Notebooks to Python

    files! •On disk it’s still the same JSON file with .ipynb extension
  13. Jupyter Visual Debugger •Implement in your favourite IDE •Try it

    in PyCharm Pro! •Questions? 68 @lisa_shashkova