468,761 Members | 1,751 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,761 developers. It's quick & easy.

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
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

Jul 26 '08 #1
0 802

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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.