Skip to content
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

Returning DISABLE from a sys.monitoring callback can trigger an assert in a debug build in (3.12b4) #106895

Closed
jpe opened this issue Jul 19, 2023 · 6 comments
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@jpe
Copy link

jpe commented Jul 19, 2023

Returning DISABLE from a sys.monitoring callback for an event >= PY_MONITORING_INSTRUMENTED_EVENTS triggers an assert in a debug build. It would probably be better to just ignore a DISABLE return value since anything else can be returned (I think) or mandate that None be returned. If the current behavior is retained, it should be documented.

I didn't test in a non debug build.

Linked PRs

@jpe jpe added the type-bug An unexpected behavior, bug, or error label Jul 19, 2023
@jpe
Copy link
Author

jpe commented Jul 19, 2023

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

@gaogaotiantian
Copy link
Member

Anything else other than DISABLE would be considered "not disable" and behave the same.

I agree that the assertion should be treated. However, the first thing is to figure out the expected behavior. For events >= PY_MONITORING_INSTRUMENTED_EVENTS, normally an exception is already set. Do we want to silently ignore the DISABLE, or send out a message to the user? Through exception or other methods? We definitely do not want to overwrite the current exception being raised, so nested exception? The current monitoring code does not even deal with errors in such case - you can return an error code and it was just ignored eventually. So maybe we don't want to raise any exceptions in monitoring code?

@AlexWaygood AlexWaygood added 3.12 bugs and security fixes 3.13 bugs and security fixes labels Jul 19, 2023
@jpe
Copy link
Author

jpe commented Jul 19, 2023

The events >= PY_MONITORING_INSTRUMENTED_EVENTS cannot be disabled per PEP 669. Note that the monitoring code is not raising an exception in this case (that's another bug) and that DISABLE is just an ordinary return value. I guess my expectation was it would just be ignored -- I have generic filtering code that was always returning DISABLE for some files. I could see maybe emitting a warning through the warning module if DISABLE was returned.

@gaogaotiantian
Copy link
Member

I'm not sure if we want to involve warning module in this case. I can accept if DISABLE is silently ignored for events that do not support it. However, it's still a design decision so let's wait for the response from @markshannon .

@markshannon
Copy link
Member

I don't think a warning makes sense.

I think we should raise, rather than ignore DISABLE.
By raising an exception we retain the ability to add disabling in future versions.

@gaogaotiantian
Copy link
Member

So we want to raise an exception from the already raised exception (as the event is for dealing with exceptions)? An ValueError maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants