-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Do not raise an Exception when exiting pdb #124703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd like to reopen this issue. The committed changes mean that quitting pdb also quits the REPL. This was mentioned on PR 124704 but I don't think there was enough discussion. It's been longstanding in Python that you can call breakpoint() in a REPL session and then return to the REPL prompt after debugging. I agree that the traceback was ugly but I think not being able to return to the REPL from pdb is a regression and a worse user experience problem than a short traceback being printed. There could be a lot of state in a REPL session that a user of older versions of Python would not expect to lose. And I at least like to jump in and out of the debugger in a REPL session a lot (admittedly in ipython, but with the new PyREPL I'd like to do it in PyREPL too!) I propose a compromise (PR 129768). The recently merged PR 124704 adds a prompt "Quit anyway? [y/n]". Since we're prompting the user now, why not let them choose how to quit? If they're stuck in an infinite loop or finished with interactive work they can choose to kill the process immediately and cleanly, but they can also exit normally (raise BdbQuit) and return to the REPL. In my proposed changes I also added some code to shorten the BdbQuit traceback. It's still ugly though, and I don't know how to remove or further improve it. |
I think the correct way to "return from breakpoint to repl" should be We can see how many people are affected by this change, because personally I never use I don't believe the PR works though, we should keep the normal path clean ( |
Thanks for the reply! I don't think I did a good job of explaining my perspective. Here's a common workflow that I use for data analysis exploration/scripting:
I prefer this workflow to a Jupyter notebook (which may also be affected), and I think I'm using iPython as designed.
That would often work, but not always. E.g. In a slow data-processing loop, I wouldn't want to continue executing the code from the breakpoint. Also, I would argue that q/quit/exit is the obvious way to leave the debugger, and it's always worked up to this point. Hopefully the user experience problem is more clear now.
I think it will affect plenty of folks with similar workflows. And I'm sceptical that removing the feature is consistent with Python's backward compatibility policy (tbh I haven't read the PEP to check).
A special case in PyREPL/REPLs could work, but I think a special case in pdb would make the most sense (or reverting, but I still think a compromise makes sense). Reading PR123757, how about adding another pdb mode, say "inline-interactive"? We can check for interactive/REPL mode in set_trace, and then when exiting in "inline-interactive" mode raise BdbQuit. When in non-interactive "inline" mode we would keep the code to kill the process and avoid the traceback. Would you be interested in a PR along those lines? |
Quick question - did you try this on ipython and confirm it will exit the shell? I don't think it will exit ipython as ipython catches |
Nope 🤦 I intended to but forgot. Indeed ipython does catch SystemExit. This is what it looks like: Thankfully it doesn't exit the process but I still think this is a worse experience than the BdbQuit traceback printed previously. SummaryWhen using breakpoint()/set_trace() in an interactive REPL session then entering q/quit/exit in pdb, previously in all cases a BdbQuit traceback was printed and the user returned to the REPL. But now:
I think the change makes the experience of doing serious work in REPLs worse. I think we could return to the previous behaviour with the following code in set_trace:
This would keep much of the benefit of the existing code while preventing the experience in REPLs from becoming worse. |
Actually on further investigation, iPython has been catching bdb.BdbQuit for a while now, so users don't even see a traceback. (I've mostly been using older versions). |
We don't need another mode, that's just too complicated. We can add the |
That also works; want me to send a PR? |
Sure, it's your idea, feel free to send a PR. I don't know how easy it is to create a regression test with repl. If it's possible, that would also be appreciated. |
…line' mode in a REPL session (#130395)
…in 'inline' mode in a REPL session (python#130395)
hi -- just ran into this for the first time -- I feel like exiting consider something like: python some_program_with_debugger.py && do-dangerous-thing previously when debugging if you quit in the middle of the program that would result in an unsuccessful exit code -- but after this patch it now exits 0 (despite the program not being successful -- in fact it was explicitly cancelled) |
I think you are right. The example might be a bit artificial but I agree a return code of something other than |
Feature or enhancement
Proposal:
Currently, if you set a
breakpoint()
in your code, and exit withq
orctrl+D
, the output is just ugly:It makes no sense to print a trackback of an exception just because I want to quit pdb and stop debugging. Now that we have an indicator for inline mode, we can deal with this.
What I propose is - for inline mode debugging, any quit attempt(
q
,ctrl+D
, etc.) will trigger a confirm prompt (likegdb
orlldb
), the user can say no and go back to debugging, or they can confirm and quit the program.There are a few design details which I will list in the following PR.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: