-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
GH-106897: Add RERAISE
event to sys.monitoring
.
#107291
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
Conversation
@gaogaotiantian would you mind reviewing this? |
If I understand the monitoring system correctly, for all the exceptions raised, we want to balance it so each Consider the following code: import sys
import asyncio
E = sys.monitoring.events
sys.monitoring.use_tool_id(0, "test")
async def async_generator():
for i in range(1):
raise ZeroDivisionError
yield i
async def main():
sys.monitoring.register_callback(0, E.EXCEPTION_HANDLED, lambda *args: print(f"EXCEPTION_HANDLED {args}"))
sys.monitoring.register_callback(0, E.RAISE, lambda *args: print(f"RAISE {args}"))
sys.monitoring.register_callback(0, E.RERAISE, lambda *args: print(f"RERAISE {args}"))
sys.monitoring.register_callback(0, E.PY_UNWIND, lambda *args: print(f"PY_UNWIND {args}"))
sys.monitoring.set_events(0, E.EXCEPTION_HANDLED | E.RAISE | E.RERAISE | E.PY_UNWIND)
try:
async for item in async_generator():
print(item)
except Exception:
pass
sys.monitoring.set_events(0, 0)
asyncio.run(main()) It prints
Maybe because we should add |
Thanks for spotting that. |
@@ -720,7 +720,11 @@ dummy_func( | |||
exc = args[0]; | |||
/* fall through */ | |||
case 0: | |||
ERROR_IF(do_raise(tstate, exc, cause), exception_unwind); | |||
if (do_raise(tstate, exc, cause)) { |
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.
I'm confused about error reporting from do_raise. If there is no exception set, it sets an exception and returns 0. What does that mean?
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.
do_raise
returns 0 if it raises, and 1 if it reraises.
Historical reasons probably 🤷
Thanks @markshannon for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @markshannon, I could not cleanly backport this to |
…07291) * Ensures that exception handling events are balanced. Each [re]raise event has a matching unwind/handled event.
GH-107346 is a backport of this pull request to the 3.12 branch. |
Fixes the imbalance between
RAISE
andEXCEPTION_HANDLED
events.