Skip to content
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

fix some extra cyclic garbage in NurseryManager #3107

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ async def __aexit__(
exc: BaseException | None,
tb: TracebackType | None,
) -> bool:
del tb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems intimidating, when you're adding a test could you add another to make sure no stackframes are getting lost? (I assume they're part of exc in addition?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tb is never needed in a context manager, and cpython are looking to deprecate the three arg form in favor of a one arg exc_value only form

new_exc = await self._nursery._nested_child_finished(exc)
# Tracebacks show the 'raise' line below out of context, so let's give
# this variable a name that makes sense out of context.
Expand All @@ -1043,7 +1044,7 @@ async def __aexit__(
value.__context__ = old_context
# delete references from locals to avoid creating cycles
# see test_cancel_scope_exit_doesnt_create_cyclic_garbage
del _, combined_error_from_nursery, value, new_exc
del _, combined_error_from_nursery, value, new_exc, exc
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I misunderstood this. There's no cycle here because exc.__traceback__ doesn't see this frame


# make sure these raise errors in static analysis if called
if not TYPE_CHECKING:
Expand Down
Loading