-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·107 lines (66 loc) · 2.37 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
import threading, argparse, time, logging
logging.basicConfig(format='[%(asctime)s][%(module)s][%(levelname)s] %(message)s', level=logging.DEBUG)
##### argparse stuff #####
parser = argparse.ArgumentParser(description='Launcher for RPi Home Controller.')
parser.add_argument("--tcp", help="Enable TCP server", action="store_true")
parser.add_argument("--http", help="Enable HTTP server", action="store_true")
parser.add_argument("--ws", help="Enable WebSocket server", action="store_true")
parser.add_argument("--ping", help="Enable Ping worker", action="store_true")
parser.add_argument("--thermostat", help="Enable Thermostat worker", action="store_true")
args = parser.parse_args()
##########
threads = []
def setupthread(thread_obj, name):
thread_obj.setDaemon(True)
thread_obj.name = name
print "starting %s thread..." % name
thread_obj.start()
threads.append(thread_obj)
def threadmonitor():
while 1:
time.sleep(600)
for thread in threads:
logging.info("%s Alive: %s" % (thread.name, thread.isAlive()))
if args.tcp:
print "importing TCP_server..."
import TCP_server
print "done"
tcp_thread = threading.Thread(target=TCP_server.main)
setupthread(tcp_thread, 'tcp')
if args.http:
print "importing HTTP_server..."
import HTTP_server
print "done"
http_thread = threading.Thread(target=HTTP_server.main)
setupthread(http_thread, 'http')
if args.ping:
print "importing ping_worker..."
import ping_worker
print "done"
ping_thread = threading.Thread(target=ping_worker.main)
setupthread(ping_thread, 'ping')
if args.thermostat:
print "importing thermostat_worker..."
import thermostat_worker
print "done"
thermostat_thread = threading.Thread(target=thermostat_worker.main)
setupthread(thermostat_thread, 'thermostat')
########## threadmonitor
threadmonitor_thread = threading.Thread(target=threadmonitor)
print "starting threadmonitor thread..."
threadmonitor_thread.setDaemon(True)
threadmonitor_thread.start()
if args.ws:
print "importing WebSocket_server..."
import WebSocket_server
print "done"
print "starting ws server on main thread..."
WebSocket_server.main()
else:
from twisted.python import log
import sys
log.startLogging(sys.stdout)
while 1:
pass
time.sleep(3600)