New submission from Martin Panter <vadmium...@gmail.com>:

See attached "leaky_generator.py" demo. Python doesn't appear to delete the 
exception variable if an exception is thrown back into it (via "throw", "close" 
or by deleting it). The result is a reference cycle that needs garbage 
collecting. This even happens when no exception variable is named. The 
exception variable is not leaked if the generator is called normally (via 
"next" or "send").

The exception variable of an exception handler is usually deleted (according to 
http://docs.python.org/py3k/reference/compound_stmts.html#the-try-statement) as 
soon as the handler is exited, even when it is not exited by simply falling 
through the end. So either this should also happen for "yield" inside the 
exception handler, or it should be documented that "yield" inside "except", 
even without "as", should be avoided.

I'm guessing this issue is specific to Python 3 because it exists for me in 
Python 3.2, 3.2.1 (both on Arch Linux) and 3.1.2 (Ubuntu) but not Python 2.7.1, 
2.7.2 (Arch) nor 2.6.5 (Ubuntu).

----------
components: Interpreter Core
files: leaky_generator.py
messages: 142515
nosy: vadmium
priority: normal
severity: normal
status: open
title: Yield" leaks exception being handled as garbage
type: resource usage
versions: Python 3.1, Python 3.2
Added file: http://bugs.python.org/file22955/leaky_generator.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue12791>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to