tests/killdaemons.py
author Thomas Arendsen Hein <thomas@intevation.de>
Sun, 16 Oct 2011 11:12:59 +0200
branchstable
changeset 15278 2ed335669e18
parent 10905 13a1b2fb7ef2
child 17464 eddfb9a550d0
permissions -rwxr-xr-x
commands: use separate try/except and try/finally as needed for python2.4 62dc0e7ab092 introduced a try/except/finally block, which breaks compatibility with python2.4

#!/usr/bin/env python

import os, 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