Mercurial > hgsubversion
comparison tests/test_util.py @ 483:37718f514acb
No os.kill() in Windows, use ctypes to call Win32 TerminateProcess()
| author | Risto Kankkunen <risto.kankkunen@iki.fi> |
|---|---|
| date | Wed, 29 Jul 2009 19:01:13 +0300 |
| parents | 83fcb1cf6d8f |
| children | 5607e81ba616 |
comparison
equal
deleted
inserted
replaced
| 482:a42fb4f1716a | 483:37718f514acb |
|---|---|
| 23 # Documentation for Subprocess.Popen() says: | 23 # Documentation for Subprocess.Popen() says: |
| 24 # "Note that on Windows, you cannot set close_fds to true and | 24 # "Note that on Windows, you cannot set close_fds to true and |
| 25 # also redirect the standard handles by setting stdin, stdout or | 25 # also redirect the standard handles by setting stdin, stdout or |
| 26 # stderr." | 26 # stderr." |
| 27 canCloseFds='win32' not in sys.platform | 27 canCloseFds='win32' not in sys.platform |
| 28 | |
| 29 if not 'win32' in sys.platform: | |
| 30 def kill_process(popen_obj): | |
| 31 os.kill(popen_obj.pid, 9) | |
| 32 else: | |
| 33 import ctypes | |
| 34 from ctypes.wintypes import BOOL, DWORD, HANDLE, UINT | |
| 35 | |
| 36 def win_status_check(result, func, args): | |
| 37 if result == 0: | |
| 38 raise ctypes.WinError() | |
| 39 return args | |
| 40 | |
| 41 def WINAPI(returns, func, *params): | |
| 42 assert len(params) % 2 == 0 | |
| 43 | |
| 44 func.argtypes = tuple(params[0::2]) | |
| 45 func.resvalue = returns | |
| 46 func.errcheck = win_status_check | |
| 47 | |
| 48 return func | |
| 49 | |
| 50 # dwDesiredAccess | |
| 51 PROCESS_TERMINATE = 0x0001 | |
| 52 | |
| 53 OpenProcess = WINAPI(HANDLE, ctypes.windll.kernel32.OpenProcess, | |
| 54 DWORD, 'dwDesiredAccess', | |
| 55 BOOL, 'bInheritHandle', | |
| 56 DWORD, 'dwProcessId', | |
| 57 ) | |
| 58 | |
| 59 CloseHandle = WINAPI(BOOL, ctypes.windll.kernel32.CloseHandle, | |
| 60 HANDLE, 'hObject' | |
| 61 ) | |
| 62 | |
| 63 TerminateProcess = WINAPI(BOOL, ctypes.windll.kernel32.TerminateProcess, | |
| 64 HANDLE, 'hProcess', | |
| 65 UINT, 'uExitCode' | |
| 66 ) | |
| 67 | |
| 68 def kill_process(popen_obj): | |
| 69 phnd = OpenProcess(PROCESS_TERMINATE, False, popen_obj.pid) | |
| 70 TerminateProcess(phnd, 1) | |
| 71 CloseHandle(phnd) | |
| 28 | 72 |
| 29 # Fixtures that need to be pulled at a subdirectory of the repo path | 73 # Fixtures that need to be pulled at a subdirectory of the repo path |
| 30 subdir = {'truncatedhistory.svndump': '/project2', | 74 subdir = {'truncatedhistory.svndump': '/project2', |
| 31 'fetch_missing_files_subdir.svndump': '/foo', | 75 'fetch_missing_files_subdir.svndump': '/foo', |
| 32 'empty_dir_in_trunk_not_repo_root.svndump': '/project', | 76 'empty_dir_in_trunk_not_repo_root.svndump': '/project', |
