##// 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 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 8 # Kill off any leftover daemon processes
6 9 try:
7 fp = open(os.environ['DAEMON_PIDS'])
10 fp = open(pidfile)
8 11 for line in fp:
9 12 try:
10 13 pid = int(line)
@@ -12,14 +15,26 b' try:'
12 15 continue
13 16 try:
14 17 os.kill(pid, 0)
18 logfn('# Killing daemon process %d' % pid)
15 19 os.kill(pid, signal.SIGTERM)
20 if tryhard:
16 21 for i in range(10):
17 22 time.sleep(0.05)
18 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 28 os.kill(pid, signal.SIGKILL)
20 29 except OSError, err:
21 30 if err.errno != errno.ESRCH:
22 31 raise
23 32 fp.close()
33 if remove:
34 os.unlink(pidfile)
24 35 except IOError:
25 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