tests/killdaemons.py
author Greg Ward <greg@gerg.ca>
Thu, 05 Jun 2014 22:11:04 -0400
changeset 978 8328337d23b2
parent 7 cc592295900f
child 1222 88e61e45026d
permissions -rwxr-xr-x
docs: add new user guide This has also been reviewed to death on evolve-testers. There are still a couple of short sections to write (clearly marked "TODO"), and one example to add. But (if I may be so bold) this is a gigantic improvement over the current docs, so it really should get merged. Incidentally, the figures are all SVG files created with Inkscape. They're not perfect, but they're pretty nice. Anyone who knows a better way to create technical diagrams is welcome to contribute. One wart: there's a test script that accompanies the document and largely duplicates it, but I haven't unified them. I've been concentrating on writing the best possible content, not on fiddling with tools. I suspect that unifying them will be non-trivial, but definitely worth doing.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
#!/usr/bin/env python
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
import os, time, errno, signal
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
# Kill off any leftover daemon processes
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
try:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
    fp = open(os.environ['DAEMON_PIDS'])
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
    for line in fp:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
        try:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
            pid = int(line)
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
        except ValueError:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
            continue
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
        try:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
            os.kill(pid, 0)
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
            os.kill(pid, signal.SIGTERM)
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    16
            for i in range(10):
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    17
                time.sleep(0.05)
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
                os.kill(pid, 0)
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
            os.kill(pid, signal.SIGKILL)
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    20
        except OSError, err:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
            if err.errno != errno.ESRCH:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    22
                raise
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    23
    fp.close()
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    24
except IOError:
cc592295900f Add write protocol support for private.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    25
    pass