From: Vinay Sajip Date: Tue, 17 Jun 2008 11:02:14 +0000 (+0000) Subject: Bug #3126: StreamHandler and FileHandler check before calling "flush" and "close... X-Git-Tag: v2.6b1~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8f96b8ec4303d5c54b9a20c963292dd98bf3a714;p=thirdparty%2FPython%2Fcpython.git Bug #3126: StreamHandler and FileHandler check before calling "flush" and "close" that the stream object has these, using hasattr (thanks to bobf for the patch). --- diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 38bbae036fff..c0b20ea01c13 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -735,7 +735,7 @@ class StreamHandler(Handler): """ Flushes the stream. """ - if self.stream: + if self.stream and hasattr(self.stream, "flush"): self.stream.flush() def emit(self, record): @@ -791,7 +791,8 @@ class FileHandler(StreamHandler): """ if self.stream: self.flush() - self.stream.close() + if hasattr(self.stream, "close"): + self.stream.close() StreamHandler.close(self) self.stream = None