Skip to content

gh-142186: all-local PEP-669 events#146182

Open
P403n1x87 wants to merge 9 commits intopython:mainfrom
P403n1x87:gh-142186-pep-669-all-local-events
Open

gh-142186: all-local PEP-669 events#146182
P403n1x87 wants to merge 9 commits intopython:mainfrom
P403n1x87:gh-142186-pep-669-all-local-events

Conversation

@P403n1x87
Copy link
Copy Markdown
Contributor

@P403n1x87 P403n1x87 commented Mar 19, 2026

We make all the low-impact monitoring API events implemented by PEP-669 local on a per-code object basis. All the events can now be enabled on selected code objects. The distinction is now between instrumented and non-instrumented events, whereby the behaviour of the DISABLE sentinel value differs. For instrumented events, DISABLE will remove the instrumentation at the specific code location where the value was returned. For non-instrumented events, DISABLE will simply disable the event for the whole code object.


📚 Documentation preview 📚: https://cpython-previews--146182.org.readthedocs.build/

We make the PY_UNWIND monitoring event available as a code-local
event to allow trapping on function exit events when an exception
bubbles up. This complements the PY_RETURN event by allowing to
catch any function exit event.
We make all the events of the low-impact monitoring API local,
shifting the distinction to whether they are instrumented or
non-instrumented.
@P403n1x87 P403n1x87 force-pushed the gh-142186-pep-669-all-local-events branch from d02dc43 to 3b8e1d5 Compare March 19, 2026 18:18
Comment thread Python/instrumentation.c
@P403n1x87 P403n1x87 marked this pull request as ready for review March 23, 2026 11:36
@P403n1x87 P403n1x87 requested a review from markshannon as a code owner March 23, 2026 11:36
@P403n1x87
Copy link
Copy Markdown
Contributor Author

@markshannon apologies for pinging you again, I appreciate you might be busy with other work. I would love for this to land in main before the first beta in May if possible 🙏

@markshannon
Copy link
Copy Markdown
Member

Overall, this looks good in terms of semantics and capabilities.

I do have a problem with the naming, though. If we make all events "local", that does make the term "local" rather meaningless and terminology you use such as "instrumented local events" and "non-instrumented local events" is a bit opaque.
No user should really have to care about whether the implementation uses instrumentation or not.

Also, there is still a clear distinction between the events that can be precisely disabled and those that can only be disabled per code object.

So, with that in mind, I think we should still keep the terms "global" and "local" for the events they apply to now, and merely frame the change as "global events can now be turned on and disable on a per-code object basis".

In the docs, change "All local events can be disabled" to "All local events can be disabled per location"

It is unfortunate the functions get_local_events and set_local_events are so named as that does confuse the issue.

Sorry for taking so long to get back to this. It will get into 3.15

@P403n1x87
Copy link
Copy Markdown
Contributor Author

@markshannon many thanks for your review.

No user should really have to care about whether the implementation uses instrumentation or not.

I totally agree with this sentiment, however a feature like the low-impact monitoring API sits quite close to the "stripped wires" that it becomes tricky to avoid that. However

there is still a clear distinction between the events that can be precisely disabled and those that can only be disabled per code object.

so as requested I have made some changes to the wording in the documentation and comments to try and capture this instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants