-
Notifications
You must be signed in to change notification settings - Fork 0
/
abqwtb_d.py
55 lines (50 loc) · 1.3 KB
/
abqwtb_d.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
#!/usr/bin/env python
import go
import sys, time
from daemon import Daemon
from threading import Thread
import logging
def update_all():
try:
data = go.go(go.live())
bus.locate(data)
except:
logging.exception("Exception in Update")
raise
class WTBDaemon(Daemon):
def run(self):
while(1):
try:
thread = Thread(target = update_all)
logging.debug('running update')
thread.start()
time.sleep(15)
while(thread.isAlive()):
logging.warning('last update not finished')
time.sleep(15)
except:
logging.error(sys.exc_info()[0])
raise
if __name__ == "__main__":
try:
logging.basicConfig(filename='/home/chughes/wtb.log',level=logging.WARNING)
bus = __import__("busstop-vicinity")
daemon = WTBDaemon('/tmp/daemon-wtb.pid')
if len(sys.argv) == 2:
if 'start' == sys.argv[1]:
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
else:
print "Unknown command"
sys.exit(2)
sys.exit(0)
else:
print "usage: %s start|stop|restart" % sys.argv[0]
sys.exit(2)
except Exception as e:
logging.error(sys.exc_info()[0])
logging.error(e)
raise