mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
Fix #13449: add 'blocking' parameter to sched.scheduler.run() so that the scheduler can be used in non-blocking applications
This commit is contained in:
parent
73520d57eb
commit
556ba04a8d
5 changed files with 34 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue