From 65e03cd7b86387fc92f5c8375e3f169b27364109 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 6 Oct 2002 03:18:34 +0000 Subject: Backport 1.17: Ignore IOError exceptions when writing the message. --- Lib/warnings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/warnings.py b/Lib/warnings.py index 1e94f59..cdc290e 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -98,7 +98,10 @@ def showwarning(message, category, filename, lineno, file=None): """Hook to write a warning to a file; replace if you like.""" if file is None: file = sys.stderr - file.write(formatwarning(message, category, filename, lineno)) + try: + file.write(formatwarning(message, category, filename, lineno)) + except IOError: + pass # the file (probably stderr) is invalid - this warning gets lost. def formatwarning(message, category, filename, lineno): """Function to format a warning the standard way.""" -- cgit v0.12