Conversation
TaskGroup will wrap a GeneratorExit in the with body into an ExceptionGroup, which then won't be recognized right by the enclosing generator's machinery. Fix this by unwrapping an ExceptionGroup if it contains *only* a GeneratorExit that was raised by the context body. This means that the straightforward case still works cleanly but we don't ever throw away exceptions from tasks. Previously we were handling this case with a second decorator, just in `merge`, but I've been seeing this error in other places hit logs while working on seal. This is a known issue in Python but there doesn't seem to quite have been consensus on what the fix is? This not quite what Yury proposed in python/cpython#135736 (comment), which is to *always* propagate GeneratorExit directly, and to call `loop.call_exception_handler()` if there are any exceptions in tasks. I prefer the version in this PR because it keeps the task errors reported while still covering the common case, but I could be missing something. @1st1? If we like this approach then maybe we should suggest it as the fix for the cpython issue? (There might also be some reason why it is suitable for our use but not as the default?)
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
anbuzin
approved these changes
Jun 18, 2026
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.
TaskGroup will wrap a GeneratorExit in the with body into an
ExceptionGroup, which then won't be recognized right by the enclosing
generator's machinery.
Fix this by unwrapping an ExceptionGroup if it contains only a
GeneratorExit that was raised by the context body. This means that the
straightforward case still works cleanly but we don't ever throw away
exceptions from tasks.
Previously we were handling this case with a second decorator, just in
merge, but I've been seeing this error in other places hit logswhile working on seal.
This is a known issue in Python but there doesn't seem to quite have
been consensus on what the fix is?
This not quite what Yury proposed in
python/cpython#135736 (comment),
which is to always propagate GeneratorExit directly, and to call
loop.call_exception_handler()if there are any exceptions in tasks.I prefer the version in this PR because it keeps the task errors
reported while still covering the common case, but I could be missing
something. @1st1?
If we like this approach then maybe we should suggest it as the fix
for the cpython issue?
(There might also be some reason why it is suitable for our use but
not as the default?)