-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigit.py
51 lines (33 loc) · 915 Bytes
/
digit.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
#!/usr/bin/env python
import time, atexit
import logging
logger = logging.getLogger(__name__)
from apscheduler.scheduler import Scheduler
import config
import inetServer
import scheduleData
from threading import Thread
import contextlib
import daemon
from BaseHTTPServer import (HTTPServer, BaseHTTPRequestHandler)
def do_main_program():
do_scheduler()
# read config and init sensors
global sensors
sensors = config.readConfig()
logger.debug(sensors.keys())
threadHTTP = Thread(target=inetServer.threadHTTP)
threadHTTP.setDaemon(True)
threadHTTP.start()
while 1:
try:
time.sleep(0.1)
except KeyboardInterrupt:
print >> sys.stderr, '\nExiting by user request.\n'
sys.exit(0)
def do_scheduler():
config.sched = Scheduler(daemon=True)
atexit.register(lambda: config.sched.shutdown(wait=False))
config.sched.start()
if __name__ == '__main__':
do_main_program()