Message226058
In Lib/warnings.py the _show_warning function catches IOError with the commented intention to ward against an "invalid file":
def _show_warning(message, category, filename, lineno, file=None, line=None):
"""Hook to write a warning to a file; replace if you like."""
if file is None:
file = sys.stderr
try:
file.write(formatwarning(message, category, filename, lineno, line))
except IOError:
pass # the file (probably stderr) is invalid - this warning gets lost.
If for some reason the file like object, and in the default case stderr, is closed, a calling program is faced with a ValueError, which is not being caught.
It seems to me, and correct me if I am wrong, that a file object which has been closed is a case of an "invalid file" and that the warning subsystem should in that case behave in the same manner as in the case of the IOError.
This behavior is the same for python 3.2 with the function renamed to showwarning and can be reproduced with for example
from sys import stderr
from warnings import warn
stderr.close()
try:
warn("foo")
except ValueError as e:
print(e) |
|
Date |
User |
Action |
Args |
2014-08-29 12:29:03 | Julius.Lehmann-Richter | set | recipients:
+ Julius.Lehmann-Richter |
2014-08-29 12:29:03 | Julius.Lehmann-Richter | set | messageid: <1409315343.62.0.0672695786427.issue22298@psf.upfronthosting.co.za> |
2014-08-29 12:29:03 | Julius.Lehmann-Richter | link | issue22298 messages |
2014-08-29 12:29:03 | Julius.Lehmann-Richter | create | |
|