diff --git a/Lib/sched.py b/Lib/sched.py --- a/Lib/sched.py +++ b/Lib/sched.py @@ -83,8 +83,10 @@ """Check whether the queue is empty.""" return not self._queue - def run(self): + def run(self, async=False): """Execute events until the queue is empty. + If async is True executes the scheduled events due to expire + soonest (if any) and then return. When there is a positive delay until the first event, the delay function is called and the event is left in the queue; @@ -114,6 +116,8 @@ time, priority, action, argument = checked_event = q[0] now = timefunc() if now < time: + if async: + return delayfunc(time - now) else: event = pop(q)