Author grahamd
Recipients OG7, grahamd, i000, jnoller
Date 2009-06-10.11:39:20
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1244633962.33.0.273396204789.issue5313@psf.upfronthosting.co.za>
In-reply-to
Content
Worth noting is that Python documentation in:

http://docs.python.org/library/stdtypes.html

says:

"""
file.fileno()
Return the integer “file descriptor” that is used by the underlying 
implementation to request I/O operations from the operating system. This 
can be useful for other, lower level interfaces that use file 
descriptors, such as the fcntl module or os.read() and friends.

Note File-like objects which do not have a real file descriptor should 
not provide this method!
"""

So, if sys.stdin is replaced with a file like object, then the code 
should not be assuming that fileno() even exists.

At the moment the code doesn't check for AttributeError which is what is 
going to be raised for trying to access non existent fileno() method.

"""
>>> import StringIO
>>> s=StringIO.StringIO("xxx")
>>> s.fileno()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: StringIO instance has no attribute 'fileno'
"""

Thus error propagates. The better check though would be to use:

    def _bootstrap(self):
       ....
            if sys.stdin is not None and hasattr(sys.stdin, "fileno"):
                try:
                    os.close(sys.stdin.fileno())
                except (OSError, ValueError):
                    pass

That is, only actually call fileno() if it is present.

This would solve the problem for the original reported issue by making 
it actually adhere to what Python documentation says about existence of 
fileno().

This change wouldn't necessarily solve other peoples related issues 
though.
History
Date User Action Args
2009-06-10 11:39:22grahamdsetrecipients: + grahamd, OG7, jnoller, i000
2009-06-10 11:39:22grahamdsetmessageid: <1244633962.33.0.273396204789.issue5313@psf.upfronthosting.co.za>
2009-06-10 11:39:21grahamdlinkissue5313 messages
2009-06-10 11:39:20grahamdcreate