8000 gh-124703: Do not raise an exception when quitting pdb by gaogaotiantian · Pull Request #124704 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-124703: Do not raise an exception when quitting pdb #124704

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

Merged
merged 5 commits into from
Jan 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use lower + strip
  • Loading branch information
gaogaotiantian committed Sep 27, 2024
commit 63a6bf6205d30878133b7897a3a9bec017e8efb9
3 changes: 2 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1727,10 +1727,11 @@ def do_quit(self, arg):
while True:
try:
reply = input('Quitting pdb will kill the process. Quit anyway? [y/n] ')
reply = reply.lower().strip()
except EOFError:
reply = 'y'
self.message('')
if reply.lower() == 'y' or reply == '':
if reply == 'y' or reply == '':
os._exit(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd prefer sys.exit here. os._exit may lead to unreleased resources. If the user wants to kill the process faster, they can hit Ctrl-C or Ctrl-\ after.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always possible to have unreleased resources - we can't prevent that with SystemExit. It may get better in some cases, but raising SystemExit in an arbitrary place of the code does not seem like a very safe way to end the program to me. The only way to make sure all resources are released (if the program is written correctly) is to continue the program.

One of the problem of SystemExit is:

while True:
    try:
        breakpoint()
    except:
        pass

This will trap in debugger forever. I know this example is a bit artificial, but it's not that rare for programs to handle SystemExit, and it's frustrating for users to be stuck in the debugger when they just want to quit.

We have a warning for the users already and they should be aware that they are "killing" a process - which means the resources could potentially be leaked. At least they'll know the process will definitely be killed after they say yes.

Of course that's my thought, and is open to more discussion.

elif reply.lower() == 'n':
return
Expand Down
Loading
0