def timed_range(seconds,period,event=None):
"""
Method used to execute the content of a for loop at periodic intervals.
For X seconds, this method will return each period fragment.
event can be used to pass a threading.Event to abort the loop if needed.
Usage:
for t in trange(15,0.1):
method_executed_at_10Hz_for_15s()
"""
t0 = time.time()
diff = 0
e = event or threading.Event()
while diff<seconds and not e.is_set():
e.wait(period)
diff = time.time()-t0
if not e.is_set:
yield diff
评论列表
文章目录