windows.py 707 B

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