Convert Python 3 ResourceWarnings into exception

Piotr Dobrogost p at gmane-2014.dobrogost.net
Thu Jul 31 10:54:43 CEST 2014


Terry Reedy <tjreedy <at> udel.edu> writes:
> 
> python -W error ...
> "Raise an exception instead of printing a warning message."
> 
> You can also turn this on with the warnings module. Assuming that this 
> works for ResourceWarning, which is should, please correct the SO record.


Thanks for taking time to answer.
Please notice that OP already tried
warnings.simplefilter(action='error', category=ResourceWarning)
with no luck.

Also, in the answer, Daniel states the following:
"The ResourceWarning is indeed being generated during garbage collection,
and Python prints a message because it doesn't have a way to raise an
exception at that point."

If it were true that would have been rather unfortunate as I guess most
ResourceWarnings are being generated during garbage collection. In that case
to let users get hold on such warnings there would need to be created new
mechanism for gathering warnings (not based on exceptions as a mean of
transport).





More information about the Python-list mailing list