[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-08 Thread Roundup Robot
Roundup Robot added the comment: New changeset 09658ea0b93d by Victor Stinner in branch 'default': Close #19880: Fix a reference leak in unittest.TestCase. Explicitly break http://hg.python.org/cpython/rev/09658ea0b93d -- nosy: +python-dev resolution: -> fixed stage: -> committed/rejec

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
STINNER Victor added the comment: unittest_leak.patch: Fix the the initial bug, unittest_leak.py. I don't think that it's possible to write a generic fix for frame_ref_cycle.py. Storing sys.exc_info() to format it as a traceback later is a common pattern. Clearing a frame at function exit brea

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
STINNER Victor added the comment: I found this issue while working the memory limit feature of tracemalloc module (issue #19817). I opened #19835 to workaround an unlimited loop on PyErr_NoMemory() when Python is out of memory. See also the issue #17807 and the PEP 442 for a similar reference

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
STINNER Victor added the comment: frame_ref_cycle.py: if I understood correctly, unittest_leak.py can be simplified to this script. A frame contains a local variable which contains the frame: reference cycle. -- Added file: http://bugs.python.org/file32956/frame_ref_cycle.py _

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
Changes by STINNER Victor : Added file: http://bugs.python.org/file32955/generator_workaround.patch ___ Python tracker ___ ___ Python-bugs-lis

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
STINNER Victor added the comment: contextmanager_leak2.py: even simpler example, storing a current frame in a local variable of the frame is enough. generator_workaround.patch is another workaround: call frame.clear() when at generator exit to explicitly break the reference cycle. --

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
STINNER Victor added the comment: contextmanager_leak.py: shorter script to demonstrate the issue. Replacing "exc_info = sys.exc_info()" with "sys.exc_info()" works around the issue. -- Added file: http://bugs.python.org/file32953/contextmanager_leak.py ___

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
Changes by STINNER Victor : -- keywords: +patch Added file: http://bugs.python.org/file32952/unittest_workaround.patch ___ Python tracker ___

[issue19880] unittest: on failure, TestCase.run() keeps a reference to the exception

2013-12-03 Thread STINNER Victor
New submission from STINNER Victor: Test attached unittest_leak.py script: you will see MyException.ninstance counter increased up to 10, whereas I expect that MyException is destroyed at TestCase.run() exit. It looks like a tricky reference cycle between: - frames - exc_info local variable o