Exemplo n.º 1
0
 def CloseHandle(h):
     if sys.version_info[:2] < (3, 3):
         if type(h) != int:
             h = h.Detach()
         win32.CloseHandle(h)
     else:
         win_api.CloseHandle(h)
Exemplo n.º 2
0
 def CloseHandle(h):
     if isinstance(h, numbers.Integral):
         # Cast long to int for 64-bit Python 2.7 under Windows
         h = int(h)
     if sys.version_info[:2] < (3, 3):
         if not isinstance(h, int):
             h = h.Detach()
         win32.CloseHandle(h)
     else:
         win_api.CloseHandle(h)
Exemplo n.º 3
0
 def detach(self):
     # retrieve handle from process which currently owns it
     if self._pid == os.getpid():
         return self._handle
     proc = _winapi.OpenProcess(_winapi.PROCESS_DUP_HANDLE, False,
                                self._pid)
     try:
         return _winapi.DuplicateHandle(proc, self._handle,
                                        _winapi.GetCurrentProcess(),
                                        self._access, False,
                                        _winapi.DUPLICATE_CLOSE_SOURCE)
     finally:
         _winapi.CloseHandle(proc)
Exemplo n.º 4
0
 def __init__(self, handle, access, pid=None):
     # duplicate handle for process with given pid
     if pid is None:
         pid = os.getpid()
     proc = _winapi.OpenProcess(_winapi.PROCESS_DUP_HANDLE, False, pid)
     try:
         self._handle = _winapi.DuplicateHandle(_winapi.GetCurrentProcess(),
                                                handle, proc, access, False,
                                                0)
     finally:
         _winapi.CloseHandle(proc)
     self._access = access
     self._pid = pid