Python 3.4+Windowsosfunction
os.get_handle_inheritable()
descriptors
Windows only: returns the "inheritable" flag (a bool) of the specified Windows handle; the cross-platform counterpart for file descriptors is os.get_inheritable(). Python 3.4+.
Syntax
os.get_handle_inheritable(handle, /)
It works with Windows HANDLEs, not C descriptor numbers — for example, what msvcrt.get_osfhandle returns. It matters when passing handles to child processes via subprocess with startupinfo. In ordinary code os.get_inheritable on file descriptors is enough.
Examples
import os
print(hasattr(os, 'get_handle_inheritable') == (os.name == 'nt')) # → True (функция есть только на Windows)
r, w = os.pipe()
print(os.get_inheritable(r)) # → False (PEP 446: новые дескрипторы не наследуются)
handle = __import__('msvcrt').get_osfhandle(r) if os.name == 'nt' else None
print(os.get_handle_inheritable(handle) == os.get_inheritable(r) if handle is not None else True) # → True
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy