[issue32089] In developer mode (-X dev), ResourceWarning is only emited once per line numbers

STINNER Victor report at bugs.python.org
Tue Nov 21 08:46:03 EST 2017


STINNER Victor <victor.stinner at gmail.com> added the comment:

> If a program calls func() 1000 times in a row, they will show the same warning 1000 times.  What does it bring to have the exact same warning (and line number) displayed 1000 times instead of once? Nothing.  There is a reason the filter "default" isn't the same as "always", and it's that "always" can be completely overwhelming.

I don't know the rationale of the "always" action rather than "default". The choice was made 7 years ago, when Georg Brandl implemented the new ResourceWarning category: commit 08be72d0aa0112118b79d271479598c218adfd23.

The problem of ResourceWarning is that the warning logs where the last reference to the resource was cleared, or where the a garbage collection was triggered. Multiple resources can be created from different places, but all "die" at the same place.

In Python 3.6, I enhanced ResourceWarning to log also the traceback where the leaked resource has been created, if the tracemalloc is tracing memory allocations. When tracemalloc is used, it's useful to log ResourceWarning multiple times even if the warning itself is logged multipletimes. Well, that's an unusual usage of the ResourceWarning, we can also suggest to use -W always::ResourceWarning in that case.


> I don't agree with this.  You're comparing "-X dev" with a pydebug build of Python, not with a normal Python.

In general, I would like to offer the same experience in "development mode" (-X dev) and with a pydebug build.

For ResourceWarning, your rationale only concerns pydebug build, no?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32089>
_______________________________________


More information about the Python-bugs-list mailing list