-
Notifications
You must be signed in to change notification settings - Fork 142
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
Terminate should try to do a graceful shutdown. Fixes #1022 #1023
Conversation
I wonder if we can just call |
I don't think it's much better.
And it still has the same issue where the user can catch the exception... |
@brettcannon Do you have any advice on how to best do graceful but (ideally) non-cancelable shutdown in CPython? |
Best way to exit is https://docs.python.org/3/library/sys.html#sys.exit , but that can be interrupted. Hard exit that can't be stopped is https://docs.python.org/3/library/os.html#os._exit . There is no in-between because clean-up code during shutdown will have an opportunity to halt things if necessary. |
The problem is that to exit in this case the If we want a I think that the major thing we need to note for users is that if that's done while stopped in a breakpoint the debugging will be unavailable from that point onwards in that thread (but we do already have this issue if the user does a We should probably make this a debugger flag (such as Does creating a |
FYI |
9019a9d
to
d27eea8
Compare
Ok, this pull request has the following changes now:
|
Looks great, but rather than making it a Boolean flag, I think it would be more consistent with other debug options to have an enum here. So the default would be: "onTerminate": "kill"; but users could set: "onTerminate": "KeyboardInterrupt"; Makes it a bit more readable, and if we get asked for other methods, we can easily add them. |
d27eea8
to
a7960c9
Compare
SonarCloud Quality Gate failed. |
a7960c9
to
8278103
Compare
Please where is more information on this feature documented as I need to hook into the debugger restart process. My |
It's not designed as an extensibility point; the idea for this change was to allow the code in the process to clean up as it normally would during process shutdown, but it's not supposed to know that the shutdown is happening because the user clicked "Stop debugging" in their IDE. Thus all specifics are implementation details, and there's no actual guarantee that you'll get a graceful shutdown in any case - it's still best-effort, and the process still gets hard-killed if simulating Ctrl+C doesn't shut it down fast enough. If you want to customize the debugger workflow, you might have to intercept the DAP message stream and detect "disconnect" and "terminate" requests there to do custom processing (e.g. notifying your process to do something before propagating the message to the debug server, or even replacing it with a different message if you want to block termination) in your proxy. This can be done in different ways; if you're using VSCode, the easiest would probably be https://code.visualstudio.com/api/references/vscode-api#DebugAdapterTracker |
Note: this is still a draft.
I'd like opinions on whether this would be the best approach @int19h @karthiknadig.
Also note that the graceful shutdown can be prevented, so, the debugger should probably remain active, but when the
KeyboardInterrupt
exception escapes the tracing hook, the debugger effectively becomes disabled because python sets the tracing to None (so, we still need to see how to deal with that -- in frame eval mode it should be possible to re-enable it on a new breakpoint hit, but in tracing mode this may be harder).Maybe something with
PyThreadState_SetAsyncExc
could get the tracing back in some way.