Show More
@@ -15,17 +15,24 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 | PROCESS_QUERY_INFORMATION = 0x400 | |
|
18 | 19 | SYNCHRONIZE = 0x00100000L |
|
19 | 20 | WAIT_OBJECT_0 = 0 |
|
20 | 21 | WAIT_TIMEOUT = 258 |
|
21 | 22 | handle = ctypes.windll.kernel32.OpenProcess( |
|
22 |
PROCESS_TERMINATE|SYNCHRONIZE, |
|
|
23 | PROCESS_TERMINATE|SYNCHRONIZE|PROCESS_QUERY_INFORMATION, | |
|
24 | False, pid) | |
|
23 | 25 | if handle == 0: |
|
24 | 26 | _check(0, 87) # err 87 when process not found |
|
25 | 27 | return # process not found, already finished |
|
26 | 28 | try: |
|
27 |
|
|
|
28 | # windows error 5 when process does not exist or no access TODO | |
|
29 | r = ctypes.windll.kernel32.WaitForSingleObject(handle, 100) | |
|
30 | if r == WAIT_OBJECT_0: | |
|
31 | pass # terminated, but process handle still available | |
|
32 | elif r == WAIT_TIMEOUT: | |
|
33 | _check(ctypes.windll.kernel32.TerminateProcess(handle, -1)) | |
|
34 | else: | |
|
35 | _check(r) | |
|
29 | 36 | |
|
30 | 37 | # TODO?: forcefully kill when timeout |
|
31 | 38 | # and ?shorter waiting time? when tryhard==True |
General Comments 0
You need to be logged in to leave comments.
Login now