Back to index

enigmail  1.4.3
win32process.py
Go to the documentation of this file.
00001 from ctypes import windll, POINTER, byref, WinError
00002 from ctypes.wintypes import WINFUNCTYPE, HANDLE, DWORD, BOOL
00003 
00004 INFINITE = -1
00005 WAIT_FAILED = 0xFFFFFFFF
00006 
00007 LPDWORD = POINTER(DWORD)
00008 _GetExitCodeProcessProto = WINFUNCTYPE(BOOL, HANDLE, LPDWORD)
00009 _GetExitCodeProcess = _GetExitCodeProcessProto(("GetExitCodeProcess", windll.kernel32))
00010 def GetExitCodeProcess(h):
00011     exitcode = DWORD()
00012     r = _GetExitCodeProcess(h, byref(exitcode))
00013     if r is 0:
00014         raise WinError()
00015     return exitcode.value
00016 
00017 _WaitForMultipleObjectsProto = WINFUNCTYPE(DWORD, DWORD, POINTER(HANDLE), BOOL, DWORD)
00018 _WaitForMultipleObjects = _WaitForMultipleObjectsProto(("WaitForMultipleObjects", windll.kernel32))
00019 
00020 def WaitForAnyProcess(processes):
00021     arrtype = HANDLE * len(processes)
00022     harray = arrtype(*(int(p._handle) for p in processes))
00023 
00024     r = _WaitForMultipleObjects(len(processes), harray, False, INFINITE)
00025     if r == WAIT_FAILED:
00026         raise WinError()
00027 
00028     return processes[r], GetExitCodeProcess(int(processes[r]._handle)) <<8