This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author srid
Recipients hpk, srid, vinay.sajip
Date 2009-07-10.00:14:33
SpamBayes Score 1.372011e-07
Marked as misclassified No
Message-id <op.uwtr9peibrrvlq@double>
In-reply-to <>
On Thu, 09 Jul 2009 16:43:49 -0700, Vinay Sajip <>

> Vinay Sajip <> added the comment:
>> However, sys.stdout|err can be assigned to some thing else
>> (eg: py.test assigning it to an open file object) .. in which case it
>> is legitimate to handle (close) such objects (handles) by who
>> created it (py.test).
> @Sridhar: I disagree. Creation is not ownership. Clearly ownership is
> *initially* with the creator, but when a stream is used to initialise a
> StreamHandler, ownership of the stream passes to the StreamHandler.

Are you suggesting that the ownership of `sys.stderr` belongs to the
logging module once logging.basicConfig (that initializes a StreamHandler
with stderr) is called? That no other module/library is to close
sys.stderr even though they created it (sys.__stderr__ being the backup)?

StreamHandler can take ownership of an arbitrary stream (say, created by
the caller) passed to it, but assuming ownership of a standard stream,
that are free to be overridden by a library (such as py.test), is rather

> I pointed out in msg90148
> that file-like objects are not guaranteed to have a "closed" attribute,
> to which he has not responded.

If this bug is acknowledged as a problem, then coming up with a fix is a  
different issue. I don't know how to detect whether a stream is closed or  
not .. especially when you say that not all file-like objects have a  
'closed' attribute (BTW, which doesn't?), but this is the only solution I  
know currently:

     # some streams, such as sys.stdout|err, cannot be owned by  
     # they might have been closed by whoever customized it.
     closed = hasattr(, 'closed') and
     if and hasattr(, 'flush') and not closed:

Date User Action Args
2009-07-10 00:14:36sridsetrecipients: + vinay.sajip, hpk
2009-07-10 00:14:35sridlinkissue6333 messages
2009-07-10 00:14:33sridcreate