-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Replace usage of strict_exception_groups=False in Nursery.start #2938
Merged
Zac-HD
merged 3 commits into
python-trio:master
from
jakkdl:strict_internal_nursery_in_start
Jan 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1231,19 +1231,29 @@ async def async_fn(arg1, arg2, *, task_status=trio.TASK_STATUS_IGNORED): | |
raise RuntimeError("Nursery is closed to new arrivals") | ||
try: | ||
self._pending_starts += 1 | ||
# `strict_exception_groups=False` prevents the implementation-detail | ||
# nursery from inheriting `strict_exception_groups=True` from the | ||
# `run` option, which would cause it to wrap a pre-started() | ||
# exception in an extra ExceptionGroup. See #2611. | ||
async with open_nursery(strict_exception_groups=False) as old_nursery: | ||
task_status: _TaskStatus[Any] = _TaskStatus(old_nursery, self) | ||
thunk = functools.partial(async_fn, task_status=task_status) | ||
task = GLOBAL_RUN_CONTEXT.runner.spawn_impl( | ||
thunk, args, old_nursery, name | ||
) | ||
task._eventual_parent_nursery = self | ||
# Wait for either TaskStatus.started or an exception to | ||
# cancel this nursery: | ||
# wrap internal nursery in try-except to unroll any exceptiongroups | ||
# to avoid wrapping pre-started() exceptions in an extra ExceptionGroup. | ||
# See #2611. | ||
try: | ||
# set strict_exception_groups = True to make sure we always unwrap | ||
# *this* nursery's exceptiongroup | ||
async with open_nursery(strict_exception_groups=True) as old_nursery: | ||
task_status: _TaskStatus[Any] = _TaskStatus(old_nursery, self) | ||
thunk = functools.partial(async_fn, task_status=task_status) | ||
task = GLOBAL_RUN_CONTEXT.runner.spawn_impl( | ||
thunk, args, old_nursery, name | ||
) | ||
task._eventual_parent_nursery = self | ||
# Wait for either TaskStatus.started or an exception to | ||
# cancel this nursery: | ||
except BaseExceptionGroup as exc: | ||
if len(exc.exceptions) == 1: | ||
raise exc.exceptions[0] from None | ||
# TODO: give a deprecationwarning instead? | ||
raise TrioInternalError( | ||
"internal nursery should not have multiple tasks" | ||
) from exc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked how one of the linked PRs proposed warning in |
||
|
||
# If we get here, then the child either got reparented or exited | ||
# normally. The complicated logic is all in TaskStatus.started(). | ||
# (Any exceptions propagate directly out of the above.) | ||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think making this an internal error immediately is fine - it's possible to do this, but it's never been something we documented or that we think is reasonable to have done for some reason.