From 8f96b8ec4303d5c54b9a20c963292dd98bf3a714 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Tue, 17 Jun 2008 11:02:14 +0000 Subject: [PATCH] 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). --- Lib/logging/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 38bbae036f..c0b20ea01c 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 -- 2.50.0