diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2011-12-14 13:38:45 (GMT) |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2011-12-14 13:38:45 (GMT) |
commit | 556ba04a8d07bf9d0996410ecda809d337f51885 (patch) | |
tree | 92c16f0dfc492ed425a1fbaf2cb4655db6748645 /Lib/sched.py | |
parent | 73520d57ebfb1272d009a070191e749caebf64ae (diff) | |
download | cpython-556ba04a8d07bf9d0996410ecda809d337f51885.zip cpython-556ba04a8d07bf9d0996410ecda809d337f51885.tar.gz cpython-556ba04a8d07bf9d0996410ecda809d337f51885.tar.bz2 |
Fix #13449: add 'blocking' parameter to sched.scheduler.run() so that the scheduler can be used in non-blocking applications
Diffstat (limited to 'Lib/sched.py')
-rw-r--r-- | Lib/sched.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/sched.py b/Lib/sched.py index 5c4a7b6..5292fcf 100644 --- a/Lib/sched.py +++ b/Lib/sched.py @@ -91,8 +91,10 @@ class scheduler: with self._lock: return not self._queue - def run(self): + def run(self, blocking=True): """Execute events until the queue is empty. + If blocking is False 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; @@ -123,6 +125,8 @@ class scheduler: time, priority, action, argument, kwargs = checked_event = q[0] now = timefunc() if now < time: + if not blocking: + return delayfunc(time - now) else: event = pop(q) |