-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Generator .close does not release resources #118272
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
Comments
bisected to eb4774d using: import gc
import weakref
class Foo:
pass
f = Foo()
f_wr = weakref.ref(f)
def genfn():
a = f
yield
g = genfn()
next(g)
del f
g.close()
gc.collect()
print(f_wr) outputs:
should output:
passes on 3.11, fails on 3.12 and 3.13a6 |
iritkatriel
added a commit
to iritkatriel/cpython
that referenced
this issue
Apr 25, 2024
Thank you, @gsbrodal for the report, and @graingert for the investigation. |
iritkatriel
added a commit
that referenced
this issue
Apr 30, 2024
#118277) Co-authored-by: Thomas Grainger <[email protected]>
iritkatriel
added a commit
to iritkatriel/cpython
that referenced
this issue
Apr 30, 2024
iritkatriel
added a commit
to iritkatriel/cpython
that referenced
this issue
May 1, 2024
…access to invalid objects during GC
iritkatriel
added a commit
that referenced
this issue
May 1, 2024
… to invalid objects during GC (#118478)
iritkatriel
added a commit
that referenced
this issue
May 2, 2024
SonicField
pushed a commit
to SonicField/cpython
that referenced
this issue
May 8, 2024
… closed (python#118277) Co-authored-by: Thomas Grainger <[email protected]>
SonicField
pushed a commit
to SonicField/cpython
that referenced
this issue
May 8, 2024
…access to invalid objects during GC (python#118478)
iritkatriel
added a commit
to iritkatriel/cpython
that referenced
this issue
Jun 13, 2024
…he generator is closed (python#118451)" This reverts commit 238efbe.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
Sending a generator
.close()
in Python 3.12 does not release resources used by local variables as it used to do in earlier versions of Python. Wrapping the generator content in atry: ... except GeneratorExit: pass
releases the resources as expected.The following shows the difference in space usage between wrapping the code with
try
-except
and not.The above space measurements were done with
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)] on win32
and looking at the space usage reported by the Windows 11 Task Manager.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: