[New-bugs-announce] [issue45241] python REPL leaks local variables when an exception is thrown
Ian Henderson
report at bugs.python.org
Sun Sep 19 04:20:44 EDT 2021
New submission from Ian Henderson <ian at ianhenderson.org>:
To reproduce, copy the following code:
----
import gc
gc.collect()
objs = gc.get_objects()
for obj in objs:
try:
if isinstance(obj, X):
print(obj)
except NameError:
class X:
pass
def f():
x = X()
raise Exception()
f()
----
then open a Python REPL and paste repeatedly at the prompt. Each time the code runs, another copy of the local variable x is leaked. This was originally discovered while using PyTorch -- tensors leaked this way tend to exhaust GPU memory pretty quickly.
Version Info:
Python 3.9.7 (default, Sep 3 2021, 04:31:11)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
----------
components: Interpreter Core
messages: 402144
nosy: ianh2
priority: normal
severity: normal
status: open
title: python REPL leaks local variables when an exception is thrown
type: resource usage
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45241>
_______________________________________
More information about the New-bugs-announce
mailing list