##// 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 import os, time, errno, signal
3 import os, time, errno, signal
4
4
5 # Kill off any leftover daemon processes
5 def killdaemons(pidfile, tryhard=True, remove=False, logfn=None):
6 try:
6 if not logfn:
7 fp = open(os.environ['DAEMON_PIDS'])
7 logfn = lambda s: s
8 for line in fp:
8 # Kill off any leftover daemon processes
9 try:
9 try:
10 pid = int(line)
10 fp = open(pidfile)
11 except ValueError:
11 for line in fp:
12 continue
12 try:
13 try:
13 pid = int(line)
14 os.kill(pid, 0)
14 except ValueError:
15 os.kill(pid, signal.SIGTERM)
15 continue
16 for i in range(10):
16 try:
17 time.sleep(0.05)
18 os.kill(pid, 0)
17 os.kill(pid, 0)
19 os.kill(pid, signal.SIGKILL)
18 logfn('# Killing daemon process %d' % pid)
20 except OSError, err:
19 os.kill(pid, signal.SIGTERM)
21 if err.errno != errno.ESRCH:
20 if tryhard:
22 raise
21 for i in range(10):
23 fp.close()
22 time.sleep(0.05)
24 except IOError:
23 os.kill(pid, 0)
25 pass
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 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