471,081 Members | 926 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,081 software developers and data experts.

clearing all warning module caches in a session

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

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

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?



Jul 26 '08 #1
0 854

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by JJ_377 | last post: by
8 posts views Thread by Floris van Haaster | last post: by
6 posts views Thread by =?Utf-8?B?R2Vv?= | last post: by
1 post views Thread by anithaapr05 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.