Alex Shkop added the comment:

The issue occurs only if C implementation of _warnings is available. It is 
caused by re-use of global filters variable from _warnings when warnings is 
being re-imported.
So warnings modifies _warnings.filters on first import. Then, when you import 
warnings again it uses already modified version of _warnings.filters and adds 
same filter for the second time.

I attach a simple patch that prevents duplicates in filters. I'm not sure if 
this is a best way to fix the problem, but it works. It certainly affects 
performance of filterwarnings(), but there shouldn't be a lot of filters anyway.

Making filters a set() will solve the problem also, but will require API 
changes. Although I didn't find anywhere in documentation that warnings.filters 
should be a list, someone might rely on its .append() method.

----------
nosy: +ashkop
Added file: http://bugs.python.org/file38301/issue18383_remove_dups.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18383>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to