-
Notifications
You must be signed in to change notification settings - Fork 0
/
automaton.py
executable file
·46 lines (34 loc) · 1.1 KB
/
automaton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import logging
import signal
from lib.logger import configure_logging
from lib.util import parse_options
from lib.util import read_config
from threading import Thread
SIGEXIT = False
LOG = logging.getLogger(__name__)
class Automaton(Thread):
def __init__(self, config):
Thread.__init__(self)
self.config = config
def run(self):
LOG.info("Starting Automaton")
#TODO(pdmars): do something
def clean_exit(signum, frame):
global SIGEXIT
SIGEXIT = True
LOG.critical("Exit signal received. Exiting at the next sane time. "
"Please stand by.")
def main():
(options, args) = parse_options()
configure_logging(options.debug)
config = read_config(options.config_file)
signal.signal(signal.SIGINT, clean_exit)
automaton = Automaton(config)
automaton.start()
# wake every seconed to make sure signals are handled by the main thread
# need this due to a quirk in the way Python threading handles signals
while automaton.isAlive():
automaton.join(timeout=1.0)
if __name__ == "__main__":
main()