-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
81 lines (58 loc) · 1.61 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/python3.6
import logging
import signal
import time
from config import Config
from libchecker import LibraryCheckerThread
class ReleaseMonitor():
"""
Class responsible for controlling the libchecker threads lifecycle.
"""
def __init__(self):
self.__config = Config()
self.__threads = []
for config in self.__config.get_configs():
self.__threads.append(LibraryCheckerThread(config))
def start(self):
"""
Starts all libchecker threads.
"""
for thread in self.__threads:
thread.start()
def stop(self):
"""
Stops all libchecker threads.
"""
for thread in self.__threads:
thread.stop()
class ServiceExit(Exception):
"""
Custom exception which is used to trigger the clean exit
of all running threads and the main program.
"""
pass
def service_shutdown(signum, frame):
"""
Called when some signal is caught.
"""
logging.info("Caught signal %d", signum)
raise ServiceExit
def main():
"""
Main program.
"""
signal.signal(signal.SIGTERM, service_shutdown)
signal.signal(signal.SIGINT, service_shutdown)
logging.basicConfig(level=logging.INFO,
format="%(asctime)s: %(threadName)s - %(levelname)s - %(message)s")
logging.info("Starting main program")
monitor = ReleaseMonitor()
try:
monitor.start()
while True:
time.sleep(0.5)
except ServiceExit:
monitor.stop()
logging.info("Exiting main program")
if __name__ == "__main__":
main()