[PATCH 1 of 4] tests: kill for windows in killdaemons.py checks return values
Simon Heimberg
simohe at besonet.ch
Thu Feb 13 21:29:27 UTC 2014
# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1389989588 -3600
# Fri Jan 17 21:13:08 2014 +0100
# Node ID db87f0a6cf9e83fb7e8d66ee194c2f029faeedab
# Parent da64679bfc8a761cacb5976efba411362c8bc51e
tests: kill for windows in killdaemons.py checks return values
The return values of the windll calls are checked and when an error is
indicated, it is raised. The handle is still closed properly.
diff -r da64679bfc8a -r db87f0a6cf9e tests/killdaemons.py
--- a/tests/killdaemons.py Thu Feb 13 13:08:50 2014 +0100
+++ b/tests/killdaemons.py Fri Jan 17 21:13:08 2014 +0100
@@ -4,13 +4,30 @@
if os.name =='nt':
import ctypes
+
+ def _check(ret, expectederr=None):
+ if ret == 0:
+ winerrno = ctypes.GetLastError()
+ if winerrno == expectederr:
+ return True
+ raise ctypes.WinError(winerrno)
+
def kill(pid, logfn, tryhard=True):
logfn('# Killing daemon process %d' % pid)
PROCESS_TERMINATE = 1
handle = ctypes.windll.kernel32.OpenProcess(
PROCESS_TERMINATE, False, pid)
- ctypes.windll.kernel32.TerminateProcess(handle, -1)
- ctypes.windll.kernel32.CloseHandle(handle)
+ if handle == 0:
+ # TODO: call _check(0, expected) to check if "process not found"
+ return # process not found, already finished
+ try:
+ _check(ctypes.windll.kernel32.TerminateProcess(handle, -1), 5)
+ # windows error 5 when process does not exist or no access TODO
+ except: #re-raises
+ ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error
+ raise
+ _check(ctypes.windll.kernel32.CloseHandle(handle))
+
else:
def kill(pid, logfn, tryhard=True):
try:
More information about the Mercurial-devel
mailing list