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

OG7 report at bugs.python.org
Wed Jun 10 17:12:46 CEST 2009


OG7 <onyxg7 at users.sourceforge.net> added the comment:

Closing the stdin fd without closing the stdin file is very dangerous.
It means that stdin will now access some random resource, for example, a
pipe created with os.pipe().

Closing stdin is useful to let the parent be alone in reading from it.
It can be achieved by replacing stdin by open('/dev/null'). The original
stdin can be closed or left to be garbage collected.

The "double flush" case is impossible to handle in general. It's the
libc's responsibility for standard file objects and sockets. But it
can't be helped (except by putting a warning in the documentation) if
someone combines multiprocessing with non-fork-safe code that keeps its
own buffers and doesn't check for a pid change.

So that code in _bootstrap should be:
sys.stdin.close()
sys.stdin = open(os.devnull)

----------

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


More information about the Python-bugs-list mailing list