Mercurial > templog
annotate server/ts.py @ 88:6f4497a448e8
increase temperature logging range
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 12 Jul 2012 23:47:29 +0800 |
parents | 0f7c005b3f87 |
children | 51d889ad39a3 |
rev | line source |
---|---|
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
3 # time that the bluetooth takes to get going? |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
4 EXTRA_WAKEUP = 0 |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
5 |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
6 FETCH_TRIES = 3 |
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
7 |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
8 # avoid turning off the bluetooth etc. |
42 | 9 TESTING = False |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
10 |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 import sys |
27
dbbd503119ba
Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
26
diff
changeset
|
12 # for wrt |
dbbd503119ba
Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
26
diff
changeset
|
13 sys.path.append('/root/python') |
dbbd503119ba
Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
26
diff
changeset
|
14 import httplib |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
15 import time |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
16 import traceback |
28 | 17 import binascii |
18 import hmac | |
34 | 19 import zlib |
35 | 20 import urllib |
21 import urllib2 | |
28 | 22 |
23 import config | |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
24 |
26
d3e5934fe55c
- Move crc16 to utils and fix it
Matt Johnston <matt@ucc.asn.au>
parents:
25
diff
changeset
|
25 from utils import monotonic_time, retry, readline, crc16 |
66 | 26 import utils |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 lightblue = None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 try: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 import lightblue |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 except ImportError: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 import bluetooth |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 def get_socket(addr): |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 if lightblue: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 s = lightblue.socket() |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
37 s.connect((addr, 1)) |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
38 s.settimeout(3) |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 else: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 s = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 s.connect((addr, 1)) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
43 s.setblocking(False) |
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
44 |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 return s |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
48 @retry() |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 def fetch(sock): |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
50 print "fetch" |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 sock.send("fetch\n") |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 crc = 0 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 lines = [] |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 l = readline(sock) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 if l != 'START\n': |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 print>>sys.stderr, "Bad expected START line '%s'\n" % l.rstrip('\n') |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 return None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 crc = crc16(l, crc) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
62 while True: |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 l = readline(sock) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 crc = crc16(l, crc) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 if l == 'END\n': |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 break |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 |
27
dbbd503119ba
Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
26
diff
changeset
|
70 lines.append(l.rstrip('\n')) |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
72 print lines |
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
73 |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 l = readline(sock) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 recv_crc = None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 try: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 k, v = l.rstrip('\n').split('=') |
25
2943f62c8e62
- Make the python work on openwrt
Matt Johnston <matt@ucc.asn.au>
parents:
24
diff
changeset
|
78 print k,v |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 if k == 'CRC': |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 recv_crc = int(v) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 if recv_crc < 0 or recv_crc > 0xffff: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 recv_crc = None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 except ValueError: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 pass |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 if recv_crc is None: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 print>>sys.stderr, "Bad expected CRC line '%s'\n" % l.rstrip('\n') |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 return None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 if recv_crc != crc: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 print>>sys.stderr, "Bad CRC: calculated 0x%x vs received 0x%x\n" % (crc, recv_crc) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 return None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 |
27
dbbd503119ba
Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
26
diff
changeset
|
94 return lines |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
95 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
96 @retry() |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
97 def turn_off(sock): |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
98 if TESTING: |
42 | 99 return 99 |
47 | 100 print>>sys.stderr, "sending btoff" |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
101 sock.send("btoff\n"); |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
102 # read newline |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
103 l = readline(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
104 if not l: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
105 print>>sys.stderr, "Bad response to btoff\n" |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
106 return None |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
107 |
42 | 108 if not l.startswith('off:'): |
109 print>>sys.stderr, "Bad response to btoff '%s'\n" % l | |
110 return None | |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
111 off, next_wake = l.rstrip().split(':') |
42 | 112 print>>sys.stderr, "Next wake %s" % next_wake |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
113 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
114 return int(next_wake) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
115 |
32 | 116 @retry() |
117 def clear_meas(sock): | |
118 sock.send("clear\n"); | |
119 l = readline(sock) | |
120 if l and l.rstrip() == 'cleared': | |
121 return True | |
122 | |
123 print>>sys.stderr, "Bad response to clear %s\n" % str(l) | |
124 return False | |
125 | |
28 | 126 def send_results(lines): |
29 | 127 enc_lines = binascii.b2a_base64(zlib.compress('\n'.join(lines))) |
35 | 128 mac = hmac.new(config.HMAC_KEY, enc_lines).hexdigest() |
28 | 129 |
35 | 130 url_data = urllib.urlencode( {'lines': enc_lines, 'hmac': mac} ) |
28 | 131 con = urllib2.urlopen(config.UPDATE_URL, url_data) |
32 | 132 result = con.read(100) |
133 if result == 'OK': | |
134 return True | |
135 else: | |
136 print>>sys.stderr, "Bad result '%s'" % result | |
137 return False | |
28 | 138 |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
139 def do_comms(sock): |
25
2943f62c8e62
- Make the python work on openwrt
Matt Johnston <matt@ucc.asn.au>
parents:
24
diff
changeset
|
140 print "do_comms" |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
141 d = None |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
142 # serial could be unreliable, try a few times |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
143 for i in range(FETCH_TRIES): |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
144 d = fetch(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
145 if d: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
146 break |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
147 time.sleep(1) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
148 if not d: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
149 return |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
150 |
27
dbbd503119ba
Add some web server handling
Matt Johnston <matt@ucc.asn.au>
parents:
26
diff
changeset
|
151 res = send_results(d) |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
152 if not res: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
153 return |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
154 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
155 clear_meas(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
156 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
157 next_wake = turn_off(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
158 sock.close() |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
159 return next_wake |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
160 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
161 testcount = 0 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
162 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
163 def sleep_for(secs): |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
164 until = monotonic_time() + secs |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
165 while True: |
24
44c5ab5ea879
- some fixes for server code
Matt Johnston <matt@ucc.asn.au>
parents:
23
diff
changeset
|
166 length = until - monotonic_time() |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
167 if length <= 0: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
168 return |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
169 time.sleep(length) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
170 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
171 def main(): |
42 | 172 next_wake_time = 0 |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
173 |
65 | 174 if '--daemon' in sys.argv: |
175 utils.cheap_daemon() | |
176 | |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
177 while True: |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
178 sock = None |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
179 try: |
82
0f7c005b3f87
move server config into config.py
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
180 sock = get_socket(config.BTADDR) |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
181 except Exception, e: |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
182 print>>sys.stderr, "Error connecting:" |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
183 traceback.print_exc(file=sys.stderr) |
82
0f7c005b3f87
move server config into config.py
Matt Johnston <matt@ucc.asn.au>
parents:
66
diff
changeset
|
184 sleep_time = config.SLEEP_TIME |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
185 if sock: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
186 next_wake = None |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
187 try: |
40 | 188 next_wake_interval = do_comms(sock) |
42 | 189 next_wake_time = time.time() + next_wake_interval |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
190 except Exception, e: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
191 print>>sys.stderr, "Error in do_comms:" |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
192 traceback.print_exc(file=sys.stderr) |
42 | 193 if next_wake_time > time.time(): |
194 sleep_time = min(next_wake_time - time.time() - EXTRA_WAKEUP, sleep_time) | |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
195 |
42 | 196 print "Sleeping for %d" % sleep_time |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
197 sleep_for(sleep_time) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
198 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
199 if __name__ == '__main__': |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
200 main() |