]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 1.17:
authorRaymond Hettinger <python@rcn.com>
Sun, 6 Oct 2002 03:18:34 +0000 (03:18 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 6 Oct 2002 03:18:34 +0000 (03:18 +0000)
Ignore IOError exceptions when writing the message.

Lib/warnings.py

index 1e94f59da31e0d7d6bd00282dd2d6ff4d2a71371..cdc290e52661e0a8a4f7d39e527297b1bb8159c9 100644 (file)
@@ -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."""