[issue45241] python REPL leaks local variables when an exception is thrown

2021-09-19 Thread Ian Henderson


New submission from Ian Henderson :

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 
<https://bugs.python.org/issue45241>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45241] python REPL leaks local variables when an exception is thrown

2021-09-19 Thread Ian Henderson


Ian Henderson  added the comment:

Ah, you're right -- it looks like the 'objs' global is what's keeping these 
objects alive.  Sorry for the noise.

--
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue45241>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com