Skip to content
Snippets Groups Projects
Commit 1a4cd3de authored by jkerdreu's avatar jkerdreu
Browse files

Change timer from repeat to counter

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2215 b32b6428-25c9-4566-ad07-03861ab6144f
parent ad570c82
No related branches found
No related tags found
No related merge requests found
......@@ -49,12 +49,13 @@ class Scanner:
print("="*70)
self.loop()
print("="*70)
print("Found %d devices" % len(self.seen))
def loop(self):
t0 = time.time()
while 1:
self.eng.loop()
if time.time() > (t0 + 1):
if time.time() > (t0 + 2):
break
def parse_answer(self,msg):
......
......@@ -259,13 +259,13 @@ class Engine(object):
#####################################################
# timers
#####################################################
def add_timer(self,func,period,repeat=-1):
def add_timer(self,func,period,counter=-1):
"""
func: function to call
period: period in second
repeat: number of repeat, -1 => always
counter: number of repeat, -1 => always
"""
t = Timer(func,period,repeat)
t = Timer(func,period,counter)
self.timers.append(t)
return t
......@@ -287,9 +287,9 @@ class Engine(object):
t.func()
except CallbackError as e:
logger.error(e.description)
if (t.repeat != -1):
t.repeat = t.repeat-1
if t.repeat == 0:
if (t.counter != -1):
t.counter = t.counter-1
if t.counter == 0:
expire_list.append(t)
t.deadline = now + t.period
# delete expired timers
......@@ -414,9 +414,9 @@ def get_args_method(method):
class Timer(object):
def __init__(self,func,period,repeat):
def __init__(self,func,period,counter):
self.func = func
self.period = period
self.repeat = repeat
self.deadline = 0
self.counter = counter
self.deadline = time.time() + period
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment