##// END OF EJS Templates
run-tests: do not duplicate killdaemons() code
Patrick Mezard -
r17464:eddfb9a5 default
parent child Browse files
Show More
@@ -2,9 +2,12 b''
2
2
3 import os, time, errno, signal
3 import os, time, errno, signal
4
4
5 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
6 if not logfn:
7 logfn = lambda s: s
5 # Kill off any leftover daemon processes
8 # Kill off any leftover daemon processes
6 try:
9 try:
7 fp = open(os.environ['DAEMON_PIDS'])
10 fp = open(pidfile)
8 for line in fp:
11 for line in fp:
9 try:
12 try:
10 pid = int(line)
13 pid = int(line)
@@ -12,14 +15,26 b' try:'
12 continue
15 continue
13 try:
16 try:
14 os.kill(pid, 0)
17 os.kill(pid, 0)
18 logfn('# Killing daemon process %d' % pid)
15 os.kill(pid, signal.SIGTERM)
19 os.kill(pid, signal.SIGTERM)
20 if tryhard:
16 for i in range(10):
21 for i in range(10):
17 time.sleep(0.05)
22 time.sleep(0.05)
18 os.kill(pid, 0)
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)
19 os.kill(pid, signal.SIGKILL)
28 os.kill(pid, signal.SIGKILL)
20 except OSError, err:
29 except OSError, err:
21 if err.errno != errno.ESRCH:
30 if err.errno != errno.ESRCH:
22 raise
31 raise
23 fp.close()
32 fp.close()
33 if remove:
34 os.unlink(pidfile)
24 except IOError:
35 except IOError:
25 pass
36 pass
37
38 if __name__ == '__main__':
39 killdaemons(os.environ['DAEMON_PIDS'])
40
@@ -54,6 +54,7 b' import tempfile'
54 import time
54 import time
55 import re
55 import re
56 import threading
56 import threading
57 import killdaemons as killmod
57
58
58 processlock = threading.Lock()
59 processlock = threading.Lock()
59
60
@@ -348,29 +349,8 b' def terminate(proc):'
348 pass
349 pass
349
350
350 def killdaemons():
351 def killdaemons():
351 # Kill off any leftover daemon processes
352 return killmod.killdaemons(DAEMON_PIDS, tryhard=False, remove=True,
352 try:
353 logfn=vlog)
353 fp = open(DAEMON_PIDS)
354 for line in fp:
355 try:
356 pid = int(line)
357 except ValueError:
358 continue
359 try:
360 os.kill(pid, 0)
361 vlog('# Killing daemon process %d' % pid)
362 os.kill(pid, signal.SIGTERM)
363 time.sleep(0.1)
364 os.kill(pid, 0)
365 vlog('# Daemon process %d is stuck - really killing it' % pid)
366 os.kill(pid, signal.SIGKILL)
367 except OSError, err:
368 if err.errno != errno.ESRCH:
369 raise
370 fp.close()
371 os.unlink(DAEMON_PIDS)
372 except IOError:
373 pass
374
354
375 def cleanup(options):
355 def cleanup(options):
376 if not options.keep_tmpdir:
356 if not options.keep_tmpdir:
General Comments 0
You need to be logged in to leave comments. Login now