comparison server/utils.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
comparison
equal deleted inserted replaced
22:885532437100 23:b5925cb4f264
3 import ctypes 3 import ctypes
4 import time 4 import time
5 import select 5 import select
6 6
7 DEFAULT_TRIES = 3 7 DEFAULT_TRIES = 3
8 READLINE_SELECT_TIMEOUT = 20
8 9
9 __all__ = ('monotonic_time', 'retry') 10 __all__ = ('monotonic_time', 'retry')
10 11
11 clock_gettime = None 12 clock_gettime = None
12 no_clock_gettime = False 13 no_clock_gettime = False
41 42
42 # decorator, tries a number of times, returns None on failure, sleeps between 43 # decorator, tries a number of times, returns None on failure, sleeps between
43 # Must be used as "@retry()" if arguments are defaulted 44 # Must be used as "@retry()" if arguments are defaulted
44 def retry(retries=DEFAULT_TRIES, try_time = 1): 45 def retry(retries=DEFAULT_TRIES, try_time = 1):
45 def inner(func): 46 def inner(func):
46 print "inner"
47 def new_f(*args, **kwargs): 47 def new_f(*args, **kwargs):
48 print "newf"
49 for i in range(retries): 48 for i in range(retries):
50 print "retry %d" % i
51 d = func(*args, **kwargs) 49 d = func(*args, **kwargs)
52 if d: 50 if d:
53 return d 51 return d
54 time.sleep(try_time) 52 time.sleep(try_time)
55 new_f.func_name = func.func_name 53 new_f.func_name = func.func_name