Mercurial > templog
annotate server/ts.py @ 23:b5925cb4f264
Fix bugs in server code (try actually running it)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 04 Jun 2012 23:50:42 +0800 |
parents | 885532437100 |
children | 44c5ab5ea879 |
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 |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
3 BTADDR = "00:12:03:27:70:88" |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
4 SLEEP_TIME = 180 |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
5 # 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
|
6 EXTRA_WAKEUP = 0 |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
7 |
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. |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
9 TESTING = True |
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 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 import httplib |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
13 import time |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
14 import traceback |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
15 |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
16 from utils import monotonic_time, retry, readline |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 lightblue = None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 try: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 import lightblue |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 except ImportError: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 import bluetooth |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 def get_socket(addr): |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 if lightblue: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 s = lightblue.socket() |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
27 s.connect((addr, 1)) |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 else: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 s = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 s.connect((addr, 1)) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
32 s.setnonblocking(True) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
33 |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 return s |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 # from http://blog.stalkr.net/2011/04/pctf-2011-32-thats-no-bluetooth.html |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 def crc16(buff, crc = 0, poly = 0x8408): |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
38 l = len(buff) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
39 i = 0 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
40 while i < l: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
41 ch = ord(buff[i]) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
42 uc = 0 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
43 while uc < 8: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
44 if (crc & 1) ^ (ch & 1): |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
45 crc = (crc >> 1) ^ poly |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
46 else: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
47 crc >>= 1 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
48 ch >>= 1 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
49 uc += 1 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
50 i += 1 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
51 return crc |
21
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 |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
54 @retry() |
21
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 def fetch(sock): |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 sock.send("fetch\n") |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 crc = 0 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 lines = [] |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 l = readline(sock) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 if l != 'START\n': |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 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
|
64 return None |
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 lines.append(l) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 while true: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 l = readline(sock) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 crc = crc16(l, crc) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 if l == 'END\n': |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 break |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 lines.append(l) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 l = readline(sock) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 recv_crc = None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 try: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 k, v = l.rstrip('\n').split('=') |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 if k == 'CRC': |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 recv_crc = int(v) |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 if recv_crc < 0 or recv_crc > 0xffff: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 recv_crc = None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 except ValueError: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 pass |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 if recv_crc is None: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 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
|
91 return None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 if recv_crc != crc: |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 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
|
95 return None |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 |
2029633912c2
untested simple server proxy code
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 return ''.join(lines) |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
98 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
99 @retry() |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
100 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
|
101 if TESTING: |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
102 return None |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
103 sock.send("btoff\n"); |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
104 # read newline |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
105 l = readline(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
106 if not l: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
107 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
|
108 return None |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
109 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
110 off, next_wake = l.rstrip().split(':') |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
111 if off != 'Off': |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
112 print>>sys.stderr, "Bad response to btoff '%s'\n" % l |
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 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
116 def do_comms(sock): |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
117 d = None |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
118 # 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
|
119 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
|
120 d = fetch(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
121 if d: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
122 break |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
123 time.sleep(1) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
124 if not d: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
125 return |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
126 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
127 res = send_results() |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
128 if not res: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
129 return |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
130 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
131 clear_meas(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
132 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
133 next_wake = turn_off(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
134 sock.close() |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
135 return next_wake |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
136 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
137 testcount = 0 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
138 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
139 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
|
140 until = monotonic_time() + secs |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
141 while True: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
142 length = until < monotonic_time() |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
143 if length <= 0: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
144 return |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
145 time.sleep(length) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
146 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
147 def main(): |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
148 |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
149 while True: |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
150 sock = None |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
151 try: |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
152 sock = get_socket(BTADDR) |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
153 except Exception, e: |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
154 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
|
155 traceback.print_exc(file=sys.stderr) |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
156 sleep_time = SLEEP_TIME |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
157 if sock: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
158 next_wake = None |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
159 try: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
160 next_wake = do_comms(sock) |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
161 except Exception, e: |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
162 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
|
163 traceback.print_exc(file=sys.stderr) |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
164 if next_wake: |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
165 sleep_time = min(next_wake+EXTRA_WAKEUP, sleep_time) |
22
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
166 |
23
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
167 if TESTING: |
b5925cb4f264
Fix bugs in server code (try actually running it)
Matt Johnston <matt@ucc.asn.au>
parents:
22
diff
changeset
|
168 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
|
169 sleep_for(sleep_time) |
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 if __name__ == '__main__': |
885532437100
A bit of work on the server python
Matt Johnston <matt@ucc.asn.au>
parents:
21
diff
changeset
|
172 main() |