Skip to content

Commit

Permalink
un-inline ki protection decorator
Browse files Browse the repository at this point in the history
new f_locals method doesn't create a cycle in this situation
  • Loading branch information
richardsheridan committed May 27, 2024
1 parent dc372df commit 7f64b79
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/trio/_core/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ def _close(self, exc: BaseException | None) -> BaseException | None:
self._cancel_status = None
return exc

@enable_ki_protection
def __exit__(
self,
etype: type[BaseException] | None,
Expand All @@ -633,10 +634,6 @@ def __exit__(
# so __exit__() must be just _close() plus this logic for adapting
# the exception-filtering result to the context manager API.

# This inlines the enable_ki_protection decorator so we can fix
# f_locals *locally* below to avoid reference cycles
sys._getframe().f_locals[LOCALS_KEY_KI_PROTECTION_ENABLED] = True

# Tracebacks show the 'raise' line below out of context, so let's give
# this variable a name that makes sense out of context.
remaining_error_after_cancel_scope = self._close(exc)
Expand Down

0 comments on commit 7f64b79

Please sign in to comment.