GH-106897: Add RERAISE event to sys.monitoring.#107291
GH-106897: Add RERAISE event to sys.monitoring.#107291markshannon merged 2 commits intopython:mainfrom
RERAISE event to sys.monitoring.#107291Conversation
|
@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. |
| /* 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.
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.
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
RAISEandEXCEPTION_HANDLEDevents.