Skip to content

Add mechanism for getting active exception in a sys.monitoring PY_UNWIND callback (3.12) #106898

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

Closed
jpe opened this issue Jul 19, 2023 · 6 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@jpe
Copy link

jpe commented Jul 19, 2023

I couldn't figure out a way get the active exception from a PY_UNWIND event callback -- I was hoping the exception would be passed to the callback but it isn't. This was an issue with the old tracer function debugger / profiler support so it's not really a regression, but I was hoping to avoid the work arounds that we used with it.

I mentioned this in #103082 but was encouraged to create a separate bug for it.

Linked PRs

@jpe jpe added the type-feature A feature request or enhancement label Jul 19, 2023
@gaogaotiantian
Copy link
Member

This should be doable by simply getting the exceptions from tstate. The question is whether to add it - it would change the interface of the monitoring callbacks and is not backward compatible (of course it won't break a lot of code as there aren't a lot yet). I'll leave the decision to @markshannon and if he's lazy to implement that, I can do it.

@jpe
Copy link
Author

jpe commented Jul 19, 2023

Before the callback is called, the current_exception is saved & set to NULL and then it is restored afterwards. It might be in one of the other tstate fields, but using sys.exc_info() doesn't retrieve it.

@gaogaotiantian
Copy link
Member

Yes the current exception is saved. I meant we can do it otherwise in the instrumentation code to pass it down, it's not rocket science. This would be a design decision and Mark may have other concerns when he implemented this. That's why I said we should wait for his decision.

@markshannon
Copy link
Member

It makes sense to pass the exception to the event handler.
We pass the exception for the RAISE event, so it would make sense to do so for PY_UNWIND.

Should C_RAISE event handlers also get the exception?

@jpe
Copy link
Author

jpe commented Jul 21, 2023

I think C_RAISE handlers should get the exception as an argument for consistency sake, if nothing else

@gaogaotiantian
Copy link
Member

So we need to change the callback signatures. The feature is not even documented though (except for the PEP). That's probably a separate question but - we should have the official documentation for sys.monitoring right?

I can work on adding the exception to the callback if no one volunteers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants