[issue20032] asyncio.Future.set_exception() creates a reference cycle

2015-12-09 Thread Jean-Louis Fuchs
Jean-Louis Fuchs added the comment: Just to let you know I hit this problem in my code, simplified version: https://gist.github.com/ganwell/ce3718e5119c6e7e9b3e Of course it is only a problem because I am a ref-counting stickler. -- nosy: +Jean-Louis Fuchs

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread STINNER Victor
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 --

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread STINNER Victor
STINNER Victor added the comment: asyncio_break_ref_cycle.patch does not fix the issue on Python 3.3 (for Tulip). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20032 ___

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread Guido van Rossum
Guido van Rossum added the comment: Do you have an example of code that behaves differently with this patch? I can't find any. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20032 ___

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: +self._loop.call_soon(traceback.clear_frames, + self._exception.__traceback__) This will keep the traceback alive until called by the event loop, even if self._exception is cleared in the meantime... --

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread STINNER Victor
STINNER Victor added the comment: Do you have an example of code that behaves differently with this patch? I can't find any. I didn't check in the Python standard library, but the reference cycle is obvious, and I hate such issue. It introduces tricky issues like memory leaks. Here is an

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread Guido van Rossum
Guido van Rossum added the comment: The cycle will be cleaned up (and the message printed) when the garbage collector runs next. Your demo doesn't do anything else, so it never allocates memory, so it never runs gc.collect(). But that's only because it's a toy program. Maybe it's time to look

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread Antoine Pitrou
Antoine Pitrou added the comment: Maybe it's time to look into http://code.google.com/p/tulip/issues/detail?id=42 ? (It proposes to run gc.collect() occasionally when the loop is idle.) Is it possible to break the cycle instead? Or is the graph of references too complex for that? --

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread Guido van Rossum
Guido van Rossum added the comment: The only reasonable place to break the cycle seems to be the frame containing the set_exception() call -- but that could be app code. Looking again at what the patch actually does I think it is too big a hammer anyway -- it would break debugging tools that

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread STINNER Victor
STINNER Victor added the comment: The cycle will be cleaned up (and the message printed) when the garbage collector runs next. Oh, ok. Using the following task, the object is correctly deleted. --- @asyncio.coroutine def idle(): while 1: gc.collect() yield from

[issue20032] asyncio.Future.set_exception() creates a reference cycle

2013-12-20 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@gmail.com: -- resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20032 ___