[issue26567] ResourceWarning: Use tracemalloc to display the traceback where an object was allocated when a ResourceWarning is emitted

STINNER Victor report at bugs.python.org
Fri Mar 18 21:25:59 EDT 2016


STINNER Victor added the comment:

It looks like io.FileIO has a strong implementation of the destructor. If the object becomes alive again because of random code called in the destructor, the object is not removed.

socket and os.scandir have a classical unsafe destructor.

Moreover, I'm no more sure about the chosen design. When warnings.catch_warnings() is used and an unclosed io.FileIO is destroyed, the object is kept alive because it is stored in the "source" attribute of a warnings.WarningMessage.

I don't know if keeping WarningMessaging alive longer than the call to showwarning() (or _showarnmsg) is a common use case or not. The issue #26568 wants to promote the WarningMessage class, so some users may start to keep it alive.

An alternative is to format the object traceback and pass the traceback to WarningMessage. It requires to decide the format of the traceback (list of ..., string, something else?).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26567>
_______________________________________


More information about the Python-bugs-list mailing list