tests/killdaemons.py
author Alejandro Santos <alejolp@alejolp.com>
Sun, 05 Jul 2009 11:01:30 +0200
branchstable
changeset 1124 6a5b8503058d
parent 1123 17bcbb020dda
child 1125 20a680e7f09f
permissions -rw-r--r--
compat: use open() instead of file() everywhere [ original upstream message only for killdaemons here ]
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1123
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     1
#!/usr/bin/env python
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     2
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     3
import os, sys, time, errno, signal
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     4
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     5
# Kill off any leftover daemon processes
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     6
try:
1124
6a5b8503058d compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents: 1123
diff changeset
     7
    fp = open(os.environ['DAEMON_PIDS'])
1123
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     8
    for line in fp:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
     9
        try:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    10
            pid = int(line)
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    11
        except ValueError:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    12
            continue
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    13
        try:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    14
            os.kill(pid, 0)
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    15
            os.kill(pid, signal.SIGTERM)
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    16
            for i in range(10):
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    17
                time.sleep(0.05)
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    18
                os.kill(pid, 0)
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    19
            os.kill(pid, signal.SIGKILL)
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    20
        except OSError, err:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    21
            if err.errno != errno.ESRCH:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    22
                raise
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    23
    fp.close()
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    24
except IOError:
17bcbb020dda tests: add killdaemons helper script
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
    25
    pass