Conversation
AsyncioIntegration wraps the loop's task factory in a plain function. When the original is an eager task factory, a library that needs to know can no longer tell: asyncio has no public way to ask, so anyio compares the factory's code object with the standard library's. anyio then starts the children of a task group eagerly and the task group fails on exit. When the original factory is eager, install one built with asyncio.create_eager_task_factory() and wrap the coroutine in its task constructor. Any other task factory is wrapped as before. Fixes getsentry#7709 Assisted-By: Claude <[email protected]>
iainmcgin
marked this pull request as ready for review
September 24, 2026 18:24
This branch has not been deployed
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.
Description
AsyncioIntegrationwraps the loop's task factory in a plain function. When the original is an eager task factory, libraries can no longer tell: asyncio has no public way to ask, so anyio comparesfactory.__code__with the standard library's. anyio then starts a task group's child eagerly, and the task group fails withAttempted to exit a cancel scope that isn't the current tasks's current cancel scope.When the original factory is eager, the integration now installs one built with
asyncio.create_eager_task_factory()and wraps the coroutine in its task constructor. The task is created with the original factory's constructor, read from its closure, because before Python 3.14 the eager factory does not accepteager_start. If the closure is not what is expected, the integration falls back to the plain wrapper. When a library calls the task constructor directly, as anyio does, the constructor sets the task's name itself, because nocreate_task()follows to apply it.Issues