[issue12262] Not Inheriting File Descriptors on Windows?

sbt report at bugs.python.org
Sat Jun 4 21:31:03 CEST 2011


sbt <shibturn at gmail.com> added the comment:

Although Windows fds are not inheritable, the handles associated with fds can be made inheritable.

A workaround for the fact fds are not inheritable is the following pattern:

1) The parent process converts the fd to a handle using _get_osfhandle(fd).

2) The parent process makes the handle inheritable (if it is not already) using SetHandleInformation() or DuplicateHandle().

3) The parent process starts the child process and passes the handle number on the commandline.

4) The child process gets the handle number by parsing the commandline.

5) The child process uses _open_osfhandle(handle, flags) to convert the handle into an fd.  

Note that Python has open_osfhandle() and get_osfhandle() in the msvcrt module.  In C, _open_osfhandle() and _get_osfhandle() are declared in io.h.

----------
nosy: +sbt

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


More information about the Python-bugs-list mailing list