GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-142186: make PY_UNWIND available as a local event by P403n1x87 · Pull Request #142179 · python/cpython

Conversation

@P403n1x87

@P403n1x87 P403n1x87 commented Dec 2, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Example

import random, sys

m, e = sys.monitoring, sys.monitoring.events

m.use_tool_id(0, "debugger")

def monitor(event):
    def _(f):
        m.register_callback(0, event, f)
    return _

@monitor(e.PY_START)
def _(*_, **__):
    print("entering", sys._getframe(1))

@monitor(e.PY_UNWIND)
def _(*_, **__):
    print("exiting ", sys._getframe(1), "with exception")

def foo():
    raise RuntimeError()

def bar():
    return foo()

def baz():
    return bar()

m.set_local_events(0, random.choice([foo, bar, baz]).__code__, e.PY_UNWIND | e.PY_START)

try:
    baz()
except Exception:
    pass

# entering <frame at 0x101602f80, file 'test_py_unwind_local.py', line 34, code baz>
# exiting  <frame at 0x101602f80, file 'test_py_unwind_local.py', line 35, code baz> with exception
  • Issue: Make the PY_UNWIND monitoring event local #142186

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@P403n1x87 P403n1x87 changed the title Make PY_UNWIND available as a local event gh-142186: make PY_UNWIND available as a local event Dec 2, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Dec 2, 2025
Make the PY_UNWIND monitoring event local #142186
Closed
P403n1x87
P403n1x87 commented Dec 2, 2025
View reviewed changes
Comment thread Include/cpython/monitoring.h
Comment on lines +27 to +33
((ev) <= PY_MONITORING_EVENT_STOP_ITERATION)

#define PY_MONITORING_EVENT_PY_UNWIND 11

#define PY_MONITORING_IS_LOCAL_EVENT(ev) \
((ev) < _PY_MONITORING_LOCAL_EVENTS)

@P403n1x87 P403n1x87 Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

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.

IMO all these data should be encoded in a "table", e.g.

typedef struct _monitoring_event {
    int id;
    bool local;
    bool instrumented;
    char* name; // maybe
} monitoring_event_t;

monitoring_event_t MONITORING_EVENTS[] = { ... };

#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) (MONITORING_EVENTS[ev].instrumented)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@P403n1x87
P403n1x87 marked this pull request as ready for review December 16, 2025 13:57
@P403n1x87
P403n1x87 requested a review from markshannon as a code owner December 16, 2025 13:57
@bedevere-app bedevere-app Bot added the awaiting review label Dec 16, 2025
P403n1x87 added 2 commits March 19, 2026 12:03
@P403n1x87
Make PY_UNWIND available as a local event
07a26bd
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.
@P403n1x87
break local == instrumented assumption
1a3e828
@P403n1x87
P403n1x87 force-pushed the py-unwind-local-event branch from b5553ab to 1a3e828 Compare March 19, 2026 12:04
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 3, 2026
@P403n1x87 P403n1x87 closed this May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@P403n1x87
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.