comparison py/utils.py @ 259:26eee8591f61

long polling works
author Matt Johnston <matt@ucc.asn.au>
date Tue, 09 Jun 2015 23:27:44 +0800
parents 0a1b642e3086
children 78c542f03030
comparison
equal deleted inserted replaced
256:6d06795aefbb 259:26eee8591f61
3 #import ctypes 3 #import ctypes
4 import time 4 import time
5 import select 5 import select
6 import logging 6 import logging
7 import binascii 7 import binascii
8 import json
8 9
9 D = logging.debug 10 D = logging.debug
10 L = logging.info 11 L = logging.info
11 W = logging.warning 12 W = logging.warning
12 E = logging.error 13 E = logging.error
132 try: 133 try:
133 return float(open('/proc/uptime', 'r').read().split(' ', 1)[0]) 134 return float(open('/proc/uptime', 'r').read().split(' ', 1)[0])
134 except Exception as e: 135 except Exception as e:
135 return -1 136 return -1
136 137
137 def hexnonce(): 138
138 return binascii.hexlify(os.urandom(120)) 139 def json_load_round_float(s, **args):
140 return json.loads(s,parse_float = lambda f: round(float(f), 2), **args)