##// END OF EJS Templates
tests: killdaemons.py for windows waits for killed process to terminate...
Simon Heimberg -
r20494:ea3adeac default
parent child Browse files
Show More
@@ -15,14 +15,28 b" if os.name =='nt':"
15 15 def kill(pid, logfn, tryhard=True):
16 16 logfn('# Killing daemon process %d' % pid)
17 17 PROCESS_TERMINATE = 1
18 SYNCHRONIZE = 0x00100000L
19 WAIT_OBJECT_0 = 0
20 WAIT_TIMEOUT = 258
18 21 handle = ctypes.windll.kernel32.OpenProcess(
19 PROCESS_TERMINATE, False, pid)
22 PROCESS_TERMINATE|SYNCHRONIZE, False, pid)
20 23 if handle == 0:
21 24 # TODO: call _check(0, expected) to check if "process not found"
22 25 return # process not found, already finished
23 26 try:
24 27 _check(ctypes.windll.kernel32.TerminateProcess(handle, -1), 5)
25 28 # windows error 5 when process does not exist or no access TODO
29
30 # TODO?: forcefully kill when timeout
31 # and ?shorter waiting time? when tryhard==True
32 r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100)
33 # timeout = 100 ms
34 if r == WAIT_OBJECT_0:
35 pass # process is terminated
36 elif r == WAIT_TIMEOUT:
37 logfn('# Daemon process %d is stuck')
38 else:
39 check(r) # any error
26 40 except: #re-raises
27 41 ctypes.windll.kernel32.CloseHandle(handle) # no _check, keep error
28 42 raise
General Comments 0
You need to be logged in to leave comments. Login now