Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-142186: make PY_UNWIND available as a local event#142179

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
P403n1x87 wants to merge2 commits intopython:main
base:main
Choose a base branch
Loading
fromP403n1x87:py-unwind-local-event

Conversation

@P403n1x87
Copy link
Contributor

@P403n1x87P403n1x87 commentedDec 2, 2025
edited by bedevere-appbot
Loading

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

importrandom,sysm,e=sys.monitoring,sys.monitoring.eventsm.use_tool_id(0,"debugger")defmonitor(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")deffoo():raiseRuntimeError()defbar():returnfoo()defbaz():returnbar()m.set_local_events(0,random.choice([foo,bar,baz]).__code__,e.PY_UNWIND|e.PY_START)try:baz()exceptException: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

We make the PY_UNWIND monitoring event available as a code-localevent to allow trapping on function exit events when an exceptionbubbles up. This complements the PY_RETURN event by allowing tocatch any function exit event.
@P403n1x87P403n1x87 changed the titleMake PY_UNWIND available as a local eventgh-142186: make PY_UNWIND available as a local eventDec 2, 2025
Comment on lines +27 to +33
((ev) <= PY_MONITORING_EVENT_STOP_ITERATION)

#definePY_MONITORING_EVENT_PY_UNWIND 11

#definePY_MONITORING_IS_LOCAL_EVENT(ev) \
((ev) < _PY_MONITORING_LOCAL_EVENTS)

Copy link
ContributorAuthor

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.

typedefstruct_monitoring_event {intid;boollocal;boolinstrumented;char*name;// maybe}monitoring_event_t;monitoring_event_tMONITORING_EVENTS[]= { ... };#definePY_MONITORING_IS_INSTRUMENTED_EVENT(ev) (MONITORING_EVENTS[ev].instrumented)

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

Reviewers

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon will be requested when the pull request is marked ready for reviewmarkshannon is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@P403n1x87

[8]ページ先頭

©2009-2025 Movatter.jp