bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py#13135
Merged
miss-islington merged 5 commits intopython:masterfrom Dec 6, 2019
Merged
bpo-36820: Break unnecessary cycle in socket.py, codeop.py and dyld.py#13135miss-islington merged 5 commits intopython:masterfrom
miss-islington merged 5 commits intopython:masterfrom
Conversation
auvipy
approved these changes
May 31, 2019
Contributor
Author
|
From offline conversation @pablogsal, this was waiting on trying to get a generic way to detect these kinds of cycles. It seemed to be much harder than initially thought. |
pablogsal
added a commit
that referenced
this pull request
Nov 19, 2019
…nces of creating cycles (GH-17246) Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles. See for example GH-13135
jacobneiltaylor
pushed a commit
to jacobneiltaylor/cpython
that referenced
this pull request
Dec 5, 2019
…nces of creating cycles (pythonGH-17246) Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles. See for example pythonGH-13135
The cycle happens when an exception is raised in `socket.create_connection` as it saves the exception in a variable and then re-raise it. By removing the name when the exception is raised we remove this cycle. We cannot just remove the name before as in the happy path since we need the exception to be raised.
As the exceptions were being saved in a different name it was generating a cycle since it was own through the `__traceback__`. By unsetting them we can collect the object earlier without the need of waiting for the gc.
As the exceptions were being saved in a different name it was generating a cycle since it was own through the `__traceback__`. By unsetting them we can collect the object earlier without the need of waiting for the gc.
adfd53a to
be7ebe0
Compare
Contributor
|
@mariocj89: Status check is done, and it's a success ✅ . |
Contributor
|
Thanks @mariocj89 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Contributor
|
Thanks @mariocj89 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
|
GH-17485 is a backport of this pull request to the 3.7 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Dec 6, 2019
pythonGH-13135) Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute. https://bugs.python.org/issue36820 Automerge-Triggered-By: @pablogsal (cherry picked from commit b64334c) Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
|
GH-17486 is a backport of this pull request to the 3.8 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Dec 6, 2019
pythonGH-13135) Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute. https://bugs.python.org/issue36820 Automerge-Triggered-By: @pablogsal (cherry picked from commit b64334c) Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
miss-islington
added a commit
that referenced
this pull request
Dec 6, 2019
GH-13135) Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute. https://bugs.python.org/issue36820 Automerge-Triggered-By: @pablogsal (cherry picked from commit b64334c) Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
miss-islington
added a commit
that referenced
this pull request
Dec 6, 2019
GH-13135) Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute. https://bugs.python.org/issue36820 Automerge-Triggered-By: @pablogsal (cherry picked from commit b64334c) Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
shihai1991
pushed a commit
to shihai1991/cpython
that referenced
this pull request
Jan 31, 2020
…nces of creating cycles (pythonGH-17246) Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles. See for example pythonGH-13135
shihai1991
pushed a commit
to shihai1991/cpython
that referenced
this pull request
Jan 31, 2020
pythonGH-13135) Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the ``__traceback__`` attribute. https://bugs.python.org/issue36820 Automerge-Triggered-By: @pablogsal
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.
Break cycle generated when saving an exception in socket.py, codeop.py and dyld.py as they keep alive not only the exception but user objects through the
__traceback__attribute.https://bugs.python.org/issue36820
Automerge-Triggered-By: @pablogsal