Allow re-adding of a timer while the timer is being executed

This commit is contained in:
Kovid Goyal
2016-12-02 18:10:04 +05:30
parent 067c5f25b8
commit 9745b23607

View File

@@ -45,16 +45,13 @@ class Timers:
def __call__(self):
if self.timers:
now = monotonic()
for i, ev in enumerate(self.timers):
if ev[0] <= now:
expired_timers, waiting_timers = [], []
for ev in self.timers:
(expired_timers if ev[0] <= now else waiting_timers).append(ev)
self.timers = waiting_timers
for ev in expired_timers:
try:
ev.callback(*ev.args)
except Exception:
import traceback
traceback.print_exc()
else:
break
else:
del self.timers[:]
return
del self.timers[:i]