##// END OF EJS Templates
killdaemons: add windows implementation
Patrick Mezard -
r17465:2d4a096e default
parent child Browse files
Show More
@@ -2,6 +2,34 b''
2
2
3 import os, time, errno, signal
3 import os, time, errno, signal
4
4
5 if os.name =='nt':
6 import ctypes
7 def kill(pid, logfn, tryhard=True):
8 logfn('# Killing daemon process %d' % pid)
9 PROCESS_TERMINATE = 1
10 handle = ctypes.windll.kernel32.OpenProcess(
11 PROCESS_TERMINATE, False, pid)
12 ctypes.windll.kernel32.TerminateProcess(handle, -1)
13 ctypes.windll.kernel32.CloseHandle(handle)
14 else:
15 def kill(pid, logfn, tryhard=True):
16 try:
17 os.kill(pid, 0)
18 logfn('# Killing daemon process %d' % pid)
19 os.kill(pid, signal.SIGTERM)
20 if tryhard:
21 for i in range(10):
22 time.sleep(0.05)
23 os.kill(pid, 0)
24 else:
25 time.sleep(0.1)
26 os.kill(pid, 0)
27 logfn('# Daemon process %d is stuck - really killing it' % pid)
28 os.kill(pid, signal.SIGKILL)
29 except OSError, err:
30 if err.errno != errno.ESRCH:
31 raise
32
5 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
33 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
6 if not logfn:
34 if not logfn:
7 logfn = lambda s: s
35 logfn = lambda s: s
@@ -13,22 +41,7 b' def killdaemons(pidfile, tryhard=True, r'
13 pid = int(line)
41 pid = int(line)
14 except ValueError:
42 except ValueError:
15 continue
43 continue
16 try:
44 kill(pid, logfn, tryhard)
17 os.kill(pid, 0)
18 logfn('# Killing daemon process %d' % pid)
19 os.kill(pid, signal.SIGTERM)
20 if tryhard:
21 for i in range(10):
22 time.sleep(0.05)
23 os.kill(pid, 0)
24 else:
25 time.sleep(0.1)
26 os.kill(pid, 0)
27 logfn('# Daemon process %d is stuck - really killing it' % pid)
28 os.kill(pid, signal.SIGKILL)
29 except OSError, err:
30 if err.errno != errno.ESRCH:
31 raise
32 fp.close()
45 fp.close()
33 if remove:
46 if remove:
34 os.unlink(pidfile)
47 os.unlink(pidfile)
General Comments 0
You need to be logged in to leave comments. Login now