-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Avoid creating a StopIteration instance for monitoring #118692
Labels
Comments
iritkatriel
added a commit
to iritkatriel/cpython
that referenced
this issue
May 20, 2024
iritkatriel
added a commit
that referenced
this issue
May 21, 2024
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
May 24, 2024
…or monitoring (pythonGH-119216) (cherry picked from commit 6e9863d) Co-authored-by: Irit Katriel <[email protected]>
estyxx
pushed a commit
to estyxx/cpython
that referenced
this issue
Jul 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feature or enhancement
Proposal:
A new C-API for injecting monitoring events was discussed in #111997 and implemented for Py3.13 in #116413
A remaining issue is that signalling "STOP_ITERATION" events requires a
StopIteration
exception instance, whereas generators usually try to avoid creating one during termination to increase their performance.I think it would be best if CPython's monitoring infrastructure created a StopIteration instance automatically when it detects that it needs to notify about it without having one. It's in the best position to detect whether it really needs an exception instance or not. Event sources shouldn't be forced to a) figure that out themselves or b) create an instance just for it to be thrown away.
CPython already creates an exception instance for submitting a monitoring event for a generator, but does so unconditionally. It would also benefit from not having to generate one unless it's really needed for signalling.
cpython/Python/bytecodes.c
Lines 289 to 317 in 5248596
Basically, we should move the existing code from the byte code handlers all the way to the other side into the notification mechanism.
In order to report the correct StopIteration value, the event creation function should accept an object value directly, and create a
StopIteration
instance for that value only if it ends up signalling it to listeners.We might allow passing the value
NULL
(as opposed to the object valueNone
) to make the machinery look up an actually existing currently raisedStopIteration
instance. Alternatively, passing aStopIteration
instance as value is probably also a reasonably clear indication for an instance being available already. We may also consider adding two event creation functions, one with a bare stop value and one with a readily createdStopIteration
instance.This ticket proposes a usability/performance enhancement to a newly added feature in Py3.13, and thus does not fall under the "beta-1" release end of new features.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
#116413 (comment)
Linked PRs
The text was updated successfully, but these errors were encountered: