[issue3126] Lib/logging/__init__.py assumes its stream has flush and close methods

Bob Farrell report at bugs.python.org
Tue Jun 17 00:54:06 CEST 2008


New submission from Bob Farrell <robertanthonyfarrell at gmail.com>:

The documentation for the sys module says:
"stdout and stderr needn't be built-in file objects: any object is 
acceptable as long as it has a write() method that takes a string 
argument."

However, the logging module calls flush() and close() on 
StreamHandler.stream (and stream may be stdout), yet stdout does not 
apparently need to have these methods - this caused breakage for a 
program of mine that redirects stdout and can import arbitrary modules 
(it's an interactive interpreter).

The attached patch checks that these two methods exist (using hastattr) 
before calling them.

----------
components: Library (Lib)
files: __init__.py.patch
keywords: patch
messages: 68296
nosy: bobf
severity: normal
status: open
title: Lib/logging/__init__.py assumes its stream has flush and close methods
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file10640/__init__.py.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3126>
_______________________________________


More information about the Python-bugs-list mailing list