Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Reference cycle in _TracebackLogger and bug in _TracebackLogger.__del__() #155

Open

Description

@GoogleCodeExporter
Hi,

While trying to change how Trollius store tracebacks in Future.set_exception(), 
I found two bugs:

* _TracebackLogger object is never deleted if its activate() method is not 
called. It happens when run_until_complete() is used: the call to the 
activate() method is scheduled, but it will never be executed. It happens in 
many tests (test_tasks.py, test_futures.py, I don't remember which one)

* _TracebackLogger.__del__() does nothing if self.tb is None whereas self.exc 
is still known

The following patch fixes these two bugs:
http://codereview.appspot.com/69350045

Remarks:

- the patch modifies Future.__del__() to have the same output on Python 3.4: 
just add a trailing colon to the error message
- TestLoop.close() closes also BaseEventLoop.close() to clear _ready: it is 
needed in the new unit test to remove the last reference to the _TracebackLogger
- Future.set_exception()

By default (debug mode disabled), Future.set_exception() now clears the 
__traceback__ attribute of the exception to fix the reference cycle issue. So 
the log of unhandled exception doesn't contain the traceback anymore. It makes 
the debug much harder :-( But it avoids uncollectable objects in production.

To get the traceback, enable the debug mode of the event loop, but you might 
create uncollectable objects again.

I don't know what is the best choice: keep the traceback or avoid uncollectable 
objects. Is it common to use run_until_complete() and miss the call the 
activate()?

At least, the change of _TracebackLogger.__del__() must be applied.

--

Even with the patch, test_tasks.test_wait_errors() still creates uncollectable 
objects (Future, frames, TimerHandle, etc.) with Python 3.3. It's probably a 
different bug.

Original issue reported on code.google.com by victor.s...@gmail.com on 27 Feb 2014 at 5:40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions