-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainRPI.py
46 lines (39 loc) · 1.68 KB
/
mainRPI.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
import logging
import multiprocessing
import time
from rpi.logging.listener import LoggingListener
from rpi.network.server import Server
# from rpi.sensors.accelerometer import Accelerometer
from rpi.sensors.accelerometer_i2c import Accelerometer
from rpi.sensors.pressure import Pressure
from rpi.sensors.thermometer import Thermometer
from shared.customlogging.errormanager import ErrorManager
from shared.customlogging.handler import CustomQueueHandler
if __name__ == '__main__':
queue = multiprocessing.Queue(-1) # Central queue for the logs
logListen = LoggingListener(queue) # Start worker which will actually log everything
logListen.start()
# Setup logging for main process and all child processes
h = CustomQueueHandler(queue)
root = logging.getLogger()
root.addHandler(h)
root.setLevel(logging.INFO)
# Next lines starts all of the other processes and monitor them in case they quit
processClassesList = [Server, Thermometer, Pressure, Accelerometer]
processes = dict()
for processClass in processClassesList:
p = processClass()
p.start()
processes[processClass] = p
em = ErrorManager(__name__)
while True:
time.sleep(5)
for processClass, process in processes.items():
if not process.is_alive():
em.error('The process for {} exited! Trying to restart it...'.format(processClass.__name__),
processClass.__name__)
p = processClass()
p.start()
processes[processClass] = p
else:
em.resolve('{} started successfully'.format(processClass.__name__), processClass.__name__, False)