1# NOTE: win32 support is currently experimental, and not recommended 2# for production use. 3 4 5from __future__ import absolute_import, division, print_function 6import ctypes # type: ignore 7import ctypes.wintypes # type: ignore 8 9# See: http://msdn.microsoft.com/en-us/library/ms724935(VS.85).aspx 10SetHandleInformation = ctypes.windll.kernel32.SetHandleInformation 11SetHandleInformation.argtypes = (ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD, ctypes.wintypes.DWORD) 12SetHandleInformation.restype = ctypes.wintypes.BOOL 13 14HANDLE_FLAG_INHERIT = 0x00000001 15 16 17def set_close_exec(fd): 18 success = SetHandleInformation(fd, HANDLE_FLAG_INHERIT, 0) 19 if not success: 20 raise ctypes.WinError() 21