[issue27535] Ignored ResourceWarning warnings leak memory in warnings registries

STINNER Victor report at bugs.python.org
Wed Nov 22 06:29:35 EST 2017


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

The performance bottleneck of warnings.warn() is the dance between the C _warnings module and the Python warnings module. The C code retrieves many attributes, like warnings.filters, at each call, and does conversion from Python objects to C objects.

There is already a mecanism to invalidate a "cache" in the C module: warnings._filters_mutated() is called by warnings.filterwarnings() for example.

Maybe the C module could convert all filters at once into an efficient C structure, but throw this away once on cache invalidation.

The problem is that I'm not sure that it's ok to implement such deeper cache at C level. Is it part of the warnings "semantics" to allow users to modify directly warnings.filters? Must the C module always lookup in sys.modules if the 'warnings' modules didn't change?

Outside test_warnings, do you know an use case where lookup for the 'warnings' module and 'warnings.filters' must be done at *each* warnings.warn() call?

----------

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


More information about the Python-bugs-list mailing list