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 eryksun
Recipients Geass-LL, JelleZijlstra, eryksun, shihai1991, sxt1001, vstinner
Date 2022-01-22.19:57:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1642881422.21.0.230691249253.issue46454@roundup.psfhosted.org>
In-reply-to
Content
> If some one closes fd 0, then he reopens it. it will not be inherited.

In Windows, when a console process spawns a child console process without enabling handle inheritance -- e.g. subprocess.Popen(['python.exe']) -- the OS will manually duplicate (not inherit) the standard handles to the child. It doesn't matter in this case that a standard handle isn't inheritable. 

The latter also doesn't matter when any of the standard handles is overridden by a Popen() call in Windows -- e.g. subprocess.Popen(['python.exe'], stderr=DEVNULL). All of the standard handle values have to be overridden together. Popen() uses this as an opportunity to duplicate an inheritable handle for each that's not overridden, instead of just copying the handle value.

On the other hand, if subprocess.Popen() is called in Windows with handle inheritance enabled and without overriding the standard handles -- e.g. subprocess.Popen(['python.exe'], close_fds=False) -- then the standard handles should be inheritable. If any of the standard handles isn't inheritable, then at best the standard handle value in the child will be invalid or used by a handle for a kernel object type other than a file (e.g. process, event). By coincidence, however, a file open in the child could reuse the standard handle value, which can lead to buggy behavior.
History
Date User Action Args
2022-01-28 04:15:39eryksununlinkissue46454 messages
2022-01-22 19:57:02eryksunsetrecipients: + eryksun, vstinner, JelleZijlstra, shihai1991, sxt1001, Geass-LL
2022-01-22 19:57:02eryksunsetmessageid: <1642881422.21.0.230691249253.issue46454@roundup.psfhosted.org>
2022-01-22 19:57:02eryksunlinkissue46454 messages
2022-01-22 19:57:02eryksuncreate