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