refactor: change GenInfo::is_running#202
Merged
KowalskiThomas merged 1 commit intoP403n1x87:mainfrom Dec 4, 2025
Merged
Conversation
GenInfo::is_running
r1viollet
approved these changes
Dec 4, 2025
Collaborator
r1viollet
left a comment
There was a problem hiding this comment.
LGTM
Ok to iterate on this version as it will make the timeline easier to read.
Though we might want to differentiate these on_cpu cases.
Collaborator
Author
|
For posterity
Definitely agree – I initially meant to have two fields, |
KowalskiThomas
added a commit
to DataDog/dd-trace-py
that referenced
this pull request
Dec 5, 2025
## Description This change replicates P403n1x87/echion#202. This PR changes the way `GenInfo::is_running` works. Previously, it would indicate whether the _current_ coroutine was on CPU; now, it indicates whether the current coroutine _or the coroutine it (recursively) awaits_ is on CPU. Making that change also allows us to do less work when we check whether the current coroutine is on CPU or not. Because a Coroutine / Generator / `GenInfo` can only be running if it is not awaiting another Generator, we do not need to compute `is_running` if we have `await != nullptr` (and we take `await->is_running` for the value in that case). Making that change makes it easier to check whether a Task is currently on-CPU; and allows to do less work when we decide how to unwind `asyncio` Tasks (cf the changes in `TaskInfo` which doesn't need the `is_on_cpu` method that iterates on the `await` chain anymore). Note that I checked whether `GenInfo::is_running` was used in any other way than the one I describe and simplify; it is not, so I do think this change is safe to make as-is. **Note** This PR makes sense on its own, but it is in the context of making P403n1x87/echion#198 simpler. **Note** This doesn't need a changelog entry as it makes no difference to the user, it's purely a refactor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This PR changes the way
GenInfo::is_runningworks. Previously, it would indicate whether the current coroutine was on CPU; now, it indicates whether the current coroutine or the coroutine it (recursively) awaits is on CPU.Making that change also allows us to do less work when we check whether the current coroutine is on CPU or not. Because a Coroutine / Generator /
GenInfocan only be running if it is not awaiting another Generator, we do not need to computeis_runningif we haveawait != nullptr(and we takeawait->is_runningfor the value in that case).Making that change makes it easier to check whether a Task is currently on-CPU; and allows to do less work when we decide how to unwind
asyncioTasks (cf the changes inTaskInfowhich doesn't need theis_on_cpumethod that iterates on theawaitchain anymore).Note that I checked whether
GenInfo::is_runningwas used in any other way than the one I describe and simplify; it is not, so I do think this change is safe to make as-is.Note This PR makes sense on its own, but it is in the context of making #198 simpler.