2014-03-08 1:14 GMT+01:00 Jim Jewett <jimjjew...@gmail.com>:
>>> Could you clarify what the problem actually is?
>
>> Please see:
>> http://bugs.python.org/file33238/never_deleted.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
import asyncio
import gc
import sys

class MyObject:
    def __del__(self):
        print("DELETE OBJECT")

@asyncio.coroutine
def func(fut):
    obj = MyObject()
    try:
        raise ValueError()
    except Exception as err:
        fut.set_exception(err)

def collect():
    print("gc.collect")
    gc.collect()

def stop():
    print("stop!")
    loop.stop()


fut = asyncio.Future()
asyncio.Task(func(fut))
loop = asyncio.get_event_loop()
loop.call_later(2, collect)
loop.call_later(4, stop)
loop.run_forever()
loop.close()
print("exit")
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to