Message312294
Note that the CRT checks at startup whether an inherited FD is valid by calling GetFileType. If the handle is invalid or not a File, then the FD effectively is not inherited. This doesn't completely avoid the problem, since there's still a chance the handle was already assigned to a File at startup. Also, it has to skip this check if the FD is flagged as a pipe, because a pipe is likely opened in synchronous mode and blocked on a read in the parent, in which case calling GetFileType would deadlock.
For example:
>>> os.pipe()
(3, 4)
>>> os.dup2(4, 5, False) # fd 5 is still inheritable
>>> os.spawnl(os.P_WAIT, sys.executable, 'python')
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40)
[MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, msvcrt
>>> msvcrt.get_osfhandle(5)
420
Handle 420 was not inherited, so it may be unassigned, or it could be for some random kernel object. It's assigned in this case:
>>> os.get_handle_inheritable(420)
False
I have a function that calls NtQueryObject to get the type name for a kernel handle:
>>> get_type_name(420)
'Semaphore'
Now, let's model what could be a confusing bug for someone using this semaphore:
>>> os.close(5) # BUGBUG
>>> os.get_handle_inheritable(420)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [WinError 6] The handle is invalid |
|
Date |
User |
Action |
Args |
2018-02-18 02:17:48 | eryksun | set | recipients:
+ eryksun, paul.moore, tim.golden, zach.ware, steve.dower |
2018-02-18 02:17:48 | eryksun | set | messageid: <1518920268.46.0.467229070634.issue32865@psf.upfronthosting.co.za> |
2018-02-18 02:17:48 | eryksun | link | issue32865 messages |
2018-02-18 02:17:46 | eryksun | create | |
|