equal
deleted
inserted
replaced
52 import sys |
52 import sys |
53 import tempfile |
53 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 |
60 closefds = os.name == 'posix' |
61 closefds = os.name == 'posix' |
61 def Popen4(cmd, wd, timeout): |
62 def Popen4(cmd, wd, timeout): |
346 getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))() |
347 getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))() |
347 except OSError: |
348 except OSError: |
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: |
377 vlog("# Cleaning up HGTMP", HGTMP) |
357 vlog("# Cleaning up HGTMP", HGTMP) |
378 shutil.rmtree(HGTMP, True) |
358 shutil.rmtree(HGTMP, True) |