tests/killdaemons.py
author Greg Onufer <gonufer@jazzhaiku.com>
Wed, 09 Dec 2009 16:56:00 -0800
branchstable
changeset 10135 9a4034b630c4
parent 9031 3b76321aa0de
child 10905 13a1b2fb7ef2
permissions -rwxr-xr-x
patch: better handling of sequence of offset patch hunks (issue1941) The built-in patch implementation applied the hunks to the wrong lines of the file if the file in the repo has been modified to skew the patch line numbers and the file contains repetitive sequences of lines.

#!/usr/bin/env python

import os, sys, time, errno, signal

# Kill off any leftover daemon processes
try:
    fp = open(os.environ['DAEMON_PIDS'])
    for line in fp:
        try:
            pid = int(line)
        except ValueError:
            continue
        try:
            os.kill(pid, 0)
            os.kill(pid, signal.SIGTERM)
            for i in range(10):
                time.sleep(0.05)
                os.kill(pid, 0)
            os.kill(pid, signal.SIGKILL)
        except OSError, err:
            if err.errno != errno.ESRCH:
                raise
    fp.close()
except IOError:
    pass