Skip to content
Snippets Groups Projects
Commit b5f43dbf authored by Simon Heimberg's avatar Simon Heimberg
Browse files

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.
parent d0bca064
No related branches found
No related tags found
No related merge requests found
......@@ -4,8 +4,16 @@
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)
......@@ -7,10 +15,19 @@
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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment