clearing all warning module caches in a session

J

jason-sage

Hi all,

I just started using the warnings module in Python 2.5.2. When I
trigger a warning using the default warning options, an entry is created
in a module-level cache so that the warning is ignored in the future.
However, I don't see an easy way to clear or invalidate these
module-level caches of previously triggered warnings. That means that
if I ever have a warning triggered with a "once" or a default warning
level or filter, I can never see that warning again until I restart
python (or figure out what module contains the cache and delete it
manually).

I thought resetwarnings would invalidate the module-level caches, so
that I could trigger a "once" warning, then do resetwarnings() and make
the default an "always" action and see my warning displayed again. At
least, the name seems to indicate that all *warnings* would be reset,
not just the filter list. But apparently resetwarnings() just clears
the filter list, which is helpful, but doesn't do anything for the
already-cached warnings.

A very small change in the code would make this possible. Instead of
making the value of the warnings module-level cache just "1", make it an
integer which is incremented each time resetwarnings() is called. That
way calling resetwarnings() can invalidate the cache (i.e., the warnings
processing would ignore the cache record if the value wasn't the current
integer).

Again, the question is: is there an easy way to invalidate all the
module-level caches of warnings so that the entire warning system is
truly reset?

Thanks,

Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,294
Latest member
LandonPigo

Latest Threads

Top