[issue5313] multiprocessing.process using os.close(sys.stdin.fileno) instead of sys.stdin.close()

Graham Dumpleton report at bugs.python.org
Wed Jun 10 13:39:22 CEST 2009


Graham Dumpleton <Graham.Dumpleton at gmail.com> added the comment:

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.

----------

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


More information about the Python-bugs-list mailing list