question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hang after running pdb in a cell, Kernel/Interrupt doesn't help

See original GitHub issue

If you debug a cell via pdb, then don’t quit it before rerunning the cell, you can’t get back to your IPython environment. Reproduce it via Test case for pdb hang in Jupyter notebook. Here’s a screenshot:

pdb_resists_kernel_interrupt ipynb

For the record and search engines, to hang your notebook:

  • Run the following cell
  • Do not “quit” via the pdb prompt
  • Then run it again.
def test():
    import pdb; pdb.set_trace()  # XXX BREAKPOINT
    return 0

test()

Note that Kernel/Interupt doesn’t help. You can save the notebook, but to run cells again, you need to restart the kernel, at which point “All variables will be lost”

This happens to me not infrequently if I am searching thru the rest of the notebook for hints on how to debug the cell, then forget to quit before changing the cell and running it again. Yes, I can be more careful, but others have the same experience. Thanks to @wmayner for a convenient test case described at #3400.

I’m running Jupyter notebook 4.3.1 on Python 3.4.3 (default, Nov 17 2016, 01:08:31) [GCC 4.8.4] Kernel Information: Python 3.4.3 (default, Nov 17 2016, 01:08:31)

Input from @takluyver at #10499

pdb runs in the same process, and we do know when it’s expecting input. I think it needs someone to do the work so that when the HTML input box is removed in the frontend, a message is sent back to the kernel which will raise EOFError. That may need a new message type, or we could do it as a metadata field on the existing stdin reply message.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:73
  • Comments:34 (9 by maintainers)

github_iconTop GitHub Comments

18reactions
WilliamCarloscommented, Aug 22, 2018

Just got bitten by this as well. How do people typically debug in jupyter notebook? Using pdb is like juggling a grenade 😦

17reactions
danolson1commented, Jun 22, 2017

I am running into the same problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jupyter notebook stuck in pdb mode - python - Stack Overflow
It seems that the "Interrupt kernel" works like a Keyboard interrupt, forcing the output cell to refresh. Pressing i twice after the re-run...
Read more >
pdb — The Python Debugger — Python 3.11.1 documentation
After post-mortem debugging (or after normal exit of the program), pdb will restart the program. Automatic restarting preserves pdb's state (such as breakpoints) ......
Read more >
How to use the Python debugger (pdb) - Red Hat
Take a closer look at the code with step, continue, args, and breakpoints. Run the script again but using a negative number of...
Read more >
Python Debugging With Pdb
In this first example, we'll look at using pdb in its simplest form: checking the value of a variable. Insert the following code...
Read more >
Debugger — Spyder 5 documentation
You can fully control debugger execution from the Debug menu, Debug toolbar and ... A Spyder IPython console window, showing autocompletion when debugging....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found