-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
gh-131591: Implement PEP 768 #131937
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
gh-131591: Implement PEP 768 #131937
Changes from all commits
6f6b4cd
9b86022
af84100
19ef7ae
444453c
1d3ad3c
eeec1f6
fd993e3
96798c3
075ca65
45e73c5
ed2f325
6076548
a9d3ea9
e235e62
d51dda0
38a4d51
a98898d
997b557
f6dec59
d273c5b
c9a2146
4af1744
5c0b8b9
c8779cd
6889042
7f7aa8b
fbecfdb
fa98f64
5b4cb00
0dd7797
b8a0503
9344d1d
9368d38
166f4d6
d253966
8e04fdd
0c2b275
80856d3
f01d8d3
cca28c5
727a02f
6ec528c
f7e3963
40bda7c
780561b
2ab5d70
3a5f004
6346063
b442b1c
3a4ed23
8514d6e
72d3ece
9130bb8
373d4c4
bccc8a8
90ab65f
ffd340f
247e753
3c4c41c
18c2e64
139b234
4306a73
35003a8
80fab75
0905105
8db68e3
25cc486
0557de0
6dd7530
7c340e1
9096375
6516356
e6cb8fb
8b3ffa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,63 @@ If you encounter :exc:`NameError`\s or pickling errors coming out of | |
New features | ||
============ | ||
|
||
.. _whatsnew314-pep678: | ||
|
||
PEP 768: Safe external debugger interface for CPython | ||
----------------------------------------------------- | ||
|
||
:pep:`768` introduces a zero-overhead debugging interface that allows debuggers and profilers | ||
to safely attach to running Python processes. This is a significant enhancement to Python's | ||
debugging capabilities allowing debuggers to forego unsafe alternatives. | ||
|
||
The new interface provides safe execution points for attaching debugger code without modifying | ||
the interpreter's normal execution path or adding runtime overhead. This enables tools to | ||
inspect and interact with Python applications in real-time without stopping or restarting | ||
them — a crucial capability for high-availability systems and production environments. | ||
|
||
For convenience, CPython implements this interface through the :mod:`sys` module with a | ||
:func:`sys.remote_exec` function:: | ||
|
||
sys.remote_exec(pid, script_path) | ||
|
||
This function allows sending Python code to be executed in a target process at the next safe | ||
execution point. However, tool authors can also implement the protocol directly as described | ||
in the PEP, which details the underlying mechanisms used to safely attach to running processes. | ||
|
||
Here's a simple example that inspects object types in a running Python process: | ||
pablogsal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: python | ||
|
||
import os | ||
import sys | ||
import tempfile | ||
|
||
# Create a temporary script | ||
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f: | ||
script_path = f.name | ||
f.write(f"import my_debugger; my_debugger.connect({os.getpid()})") | ||
try: | ||
# Execute in process with PID 1234 | ||
print("Behold! An offering:") | ||
sys.remote_exec(1234, script_path) | ||
finally: | ||
os.unlink(script_path) | ||
Comment on lines
+128
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this example correct? Unlinking the file immediately contradicts with the function docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That example is definitely racy. |
||
|
||
The debugging interface has been carefully designed with security in mind and includes several | ||
mechanisms to control access: | ||
|
||
* A :envvar:`PYTHON_DISABLE_REMOTE_DEBUG` environment variable. | ||
* A :option:`-X disable-remote-debug` command-line option. | ||
* A :option:`--without-remote-debug` configure flag to completely disable the feature at build time. | ||
|
||
A key implementation detail is that the interface piggybacks on the interpreter's existing evaluation | ||
loop and safe points, ensuring zero overhead during normal execution while providing a reliable way | ||
for external processes to coordinate debugging operations. | ||
|
||
See :pep:`768` for more details. | ||
|
||
(Contributed by Pablo Galindo Salgado, Matt Wozniski, and Ivona Stojanovic in :gh:`131591`.) | ||
|
||
pablogsal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.. _whatsnew314-pep758: | ||
|
||
PEP 758 – Allow except and except* expressions without parentheses | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.