New submission from STINNER Victor: asyncio.Future.set_exception(exc) sets the exception attribute to exc, but exc.__traceback__ refers to frames and the current frame probably referes to the future instance.
Tell me if I'm wrong, but it looks like a reference cycle: fut -- fut.exception --> exception --exception.__traceback__ -> traceback --traceback.tb_frame --> frame --frame.fb_locals --> fut The frame class got a new clear() method in Python 3.4: http://docs.python.org/dev/reference/datamodel.html#frame.clear Maybe because of the PEP 442, the reference cycle is no more an issue. In fact, the following example calls fut destructor immediatly, at "fut = None" line. --- import asyncio fut = asyncio.Future() try: raise ValueError() except Exception as err: fut.set_exception(err) fut = None --- Attached patch breaks explicitly the reference cycle by scheduling a call to traceback.clear_frames() using call_soon(). The patch depends on asyncio_defer_format_tb.patch which is attached to the issue #19967. ---------- files: asyncio_break_ref_cycle.patch keywords: patch messages: 206672 nosy: gvanrossum, haypo, pitrou priority: normal severity: normal status: open title: asyncio.Future.set_exception() creates a reference cycle versions: Python 3.4 Added file: http://bugs.python.org/file33228/asyncio_break_ref_cycle.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20032> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com