-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
Conversation
Lib/pdb.py
Outdated
reply = 'y' | ||
self.message('') | ||
if reply == 'y' or reply == '': | ||
os._exit(0) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I'm having second thought about this. Not because of the resource release, but it seems like some people will bring up pdb in REPL, for example by running some code with |
Well, obviously |
@iritkatriel any suggestions on this feature? Thanks! |
IPython, at least, catches |
Hey @iritkatriel , any suggestions on this PR? I'm just circling back to my unmerged PRs :) |
There are a few design details, which are open to discuss:
lldb
does not trigger confirm prompt onCtrl+D
, only on commands.gdb
triggers on all. I prefer consistency sopdb
will trigger confirmation in all cases.y
/Y
as suggested in the prompt<enter>
so you can doq
,<enter>
,<enter>
Ctrl+D
so you can doCtrl+D
,Ctrl+D
gdb
andlldb
does it as well. (they do have slightly different policies on some input).n
/N
will return to debugger, all other inputs brings you back to the promptos._exit(0)
vssys.exit(0)
. I gave some thoughts about how we should exit, do we want to do it gracefully. I chose theos._exit(0)
at the end because I think when the users attach a debugger and want to quit, they don't care about whether the process will end gracefully (with all the atexit callbacks and potential exit routines), they just want to stop the process. If they want the process to run to the end, they should doc
instead ofq
.In rare cases, where a separate non-daemon thread is there or the code in a raw try ... except ... block, force exit would do well for a debugger.