[Python-Dev] What is the precise problem? [was: Reference cycles in Exception.traceback] (original) (raw)
Victor Stinner victor.stinner at gmail.com
Sat Mar 8 11:06:54 CET 2014
- Previous message: [Python-Dev] What is the precise problem? [was: Reference cycles in Exception.__traceback__]
- Next message: [Python-Dev] What is the precise problem? [was: Reference cycles in Exception.__traceback__]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2014-03-08 1:14 GMT+01:00 Jim Jewett <jimjjewett at gmail.com>:
Could you clarify what the problem actually is? Please see: http://bugs.python.org/file33238/neverdeleted.py I would not expect it to be cleared at least until go runs ... and reading the ticket, it sounds like it is cleared then.
Attached script: never_deleted2.py, it's almost the same but it explains better the problem. The script creates MyObject and Future objects which are never deleted. Calling gc.collect() does not break the reference cycle (between the future, the exception, traceback and frames). Stopping the event loop does not remove Future nor MyObject objects. Only exiting Python does remove the Future object.
The Future destructor calls code between this code fails between Python is exiting and so most symbols are set to None. I'm testing with Python 3.4 default, so with Antoine's PEP 442 and Serhiy's changes on Python shutdown (restore builtins at exit).
The Future destructor is used in asyncio to notice the developer that the application has a bug, the exception was not handled which may be a major bug.
And MyObject is not destroyed which is an obvious memory leak, beause there is no more explicit reference to it.
Script output:
gc.collect stop! exit --- Logging error --- Traceback (most recent call last): --- Logging error --- Traceback (most recent call last): Exception ignored in: <bound method Future.__del__ of Future<exception=ValueError()>> Traceback (most recent call last): File "Lib/asyncio/futures.py", line 184, in del File "Lib/asyncio/base_events.py", line 704, in call_exception_handler File "Lib/logging/init.py", line 1280, in error File "Lib/logging/init.py", line 1386, in _log File "Lib/logging/init.py", line 1396, in handle File "Lib/logging/init.py", line 1466, in callHandlers File "Lib/logging/init.py", line 837, in handle File "Lib/logging/init.py", line 961, in emit File "Lib/logging/init.py", line 890, in handleError File "Lib/traceback.py", line 169, in print_exception File "Lib/traceback.py", line 153, in _format_exception_iter File "Lib/traceback.py", line 18, in _format_list_iter File "Lib/traceback.py", line 65, in _extract_tb_or_stack_iter File "Lib/linecache.py", line 15, in getline File "Lib/linecache.py", line 41, in getlines File "Lib/linecache.py", line 126, in updatecache File "Lib/tokenize.py", line 437, in open AttributeError: 'module' object has no attribute 'open' DELETE OBJET
Victor -------------- next part -------------- A non-text attachment was scrubbed... Name: never_deleted2.py Type: text/x-python Size: 544 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20140308/bf89f064/attachment.py>
- Previous message: [Python-Dev] What is the precise problem? [was: Reference cycles in Exception.__traceback__]
- Next message: [Python-Dev] What is the precise problem? [was: Reference cycles in Exception.__traceback__]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]