comparison tests/run-tests.py @ 14821:2017495bd552 stable

run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
author Thomas Arendsen Hein <thomas@intevation.de>
date Thu, 30 Jun 2011 16:25:05 +0200
parents 259ba7502370
children 760d2dae4839
comparison
equal deleted inserted replaced
14820:7ef125fa9b35 14821:2017495bd552
76 start = time.time() 76 start = time.time()
77 while time.time() - start < timeout and p.returncode is None: 77 while time.time() - start < timeout and p.returncode is None:
78 time.sleep(1) 78 time.sleep(1)
79 p.timeout = True 79 p.timeout = True
80 if p.returncode is None: 80 if p.returncode is None:
81 try: 81 terminate(p)
82 p.terminate()
83 except OSError:
84 pass
85 threading.Thread(target=t).start() 82 threading.Thread(target=t).start()
86 83
87 return p 84 return p
88 85
89 # reserved exit code to skip test (used by hghave) 86 # reserved exit code to skip test (used by hghave)
341 if found: 338 if found:
342 vlog("# Found prerequisite", p, "at", found) 339 vlog("# Found prerequisite", p, "at", found)
343 else: 340 else:
344 print "WARNING: Did not find prerequisite tool: "+p 341 print "WARNING: Did not find prerequisite tool: "+p
345 342
343 def terminate(proc):
344 """Terminate subprocess (with fallback for Python versions < 2.6)"""
345 vlog('# Terminating process %d' % proc.pid)
346 try:
347 if hasattr(proc, 'terminate'):
348 proc.terminate()
349 else:
350 os.kill(proc.pid, signal.SIGTERM)
351 except OSError:
352 pass
353
346 def killdaemons(): 354 def killdaemons():
347 # Kill off any leftover daemon processes 355 # Kill off any leftover daemon processes
348 try: 356 try:
349 fp = open(DAEMON_PIDS) 357 fp = open(DAEMON_PIDS)
350 for line in fp: 358 for line in fp:
649 ret = proc.wait() 657 ret = proc.wait()
650 return (ret, None) 658 return (ret, None)
651 659
652 proc = Popen4(cmd, wd, options.timeout) 660 proc = Popen4(cmd, wd, options.timeout)
653 def cleanup(): 661 def cleanup():
654 try: 662 terminate(proc)
655 proc.terminate()
656 except OSError:
657 pass
658 ret = proc.wait() 663 ret = proc.wait()
659 if ret == 0: 664 if ret == 0:
660 ret = signal.SIGTERM << 8 665 ret = signal.SIGTERM << 8
661 killdaemons() 666 killdaemons()
662 return ret 667 return ret