windows.py 655 B

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