PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/core/signalapp.py

https://bitbucket.org/prologic/circuits/
Python | 48 lines | 31 code | 16 blank | 1 comment | 3 complexity | 4b9c528890c9d36111cb1dc17cdf8988 MD5 | raw file
 1#!/usr/bin/env python
 2
 3
 4import os
 5import sys
 6
 7
 8try:
 9    from coverage import coverage
10    HAS_COVERAGE = True
11except ImportError:
12    HAS_COVERAGE = False
13
14
15from circuits import Component
16from circuits.app import Daemon
17
18
19class App(Component):
20
21    def init(self, pidfile, signalfile):
22        self.pidfile = pidfile
23        self.signalfile = signalfile
24
25        Daemon(self.pidfile).register(self)
26
27    def signal(self, signal, stack):
28        f = open(self.signalfile, "w")
29        f.write(str(signal))
30        f.close()
31        self.stop()
32
33
34def main():
35    if HAS_COVERAGE:
36        _coverage = coverage(data_suffix=True)
37        _coverage.start()
38
39    pidfile = os.path.abspath(sys.argv[1])
40    signalfile = os.path.abspath(sys.argv[2])
41    App(pidfile, signalfile).run()
42
43    if HAS_COVERAGE:
44        _coverage.stop()
45        _coverage.save()
46
47if __name__ == "__main__":
48    main()