Issue
I just spent the day trying to remove this warning from my output:
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='/dev/null' mode='w' encoding='UTF-8'>
I just finished a binary search of about 100k lines of code to try to figure this out. I still haven't found what's leaving /dev/null
open, but I did find that some of our code says:
warnings.simplefilter("always")
Removing that removes the warning. Hooray! I plan to remove that bit of code, but I'm curious of two things:
Could I have avoided doing a binary search for this somehow? Enabling
TRACEMALLOC=1
was entirely ineffective (maybe because this is in third-party code we import?)Once I remove this, is there a way to list all of the warning filters that are applied at a particular point in the code? Seems like an important thing to be able to analyze, but I can't figure out how.
Solution
Just grep
for import warnings
(or the from
variant).
It's not as though that's a common thing to import.
After executing someone else's code, you can always
warnings.simplefilter("ignore")
to disable what they enabled, even without reviewing their source code.
You can view current filters in this way:
>>> import warnings
>>> import pprint
>>> pprint.pprint(warnings.filters)
[('default', None, <class 'DeprecationWarning'>, '__main__', 0),
('ignore', None, <class 'DeprecationWarning'>, None, 0),
('ignore', None, <class 'PendingDeprecationWarning'>, None, 0),
('ignore', None, <class 'ImportWarning'>, None, 0),
('ignore', None, <class 'ResourceWarning'>, None, 0)]
Answered By - J_H Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.