[Python-checkins] cpython: (sched) when run() is invoked with blocking=False return the deadline of the

giampaolo.rodola python-checkins at python.org
Thu Mar 15 13:05:46 CET 2012


http://hg.python.org/cpython/rev/59f0e6de54b3
changeset:   75693:59f0e6de54b3
user:        Giampaolo Rodola' <g.rodola at gmail.com>
date:        Thu Mar 15 13:05:41 2012 +0100
summary:
  (sched) when run() is invoked with blocking=False return the deadline of the next scheduled call in the scheduler; this use case was suggested in http://bugs.python.org/issue1641#msg149453

files:
  Doc/library/sched.rst |  3 ++-
  Lib/sched.py          |  5 +++--
  2 files changed, 5 insertions(+), 3 deletions(-)


diff --git a/Doc/library/sched.rst b/Doc/library/sched.rst
--- a/Doc/library/sched.rst
+++ b/Doc/library/sched.rst
@@ -109,7 +109,8 @@
    on until there are no more scheduled events.
 
    If *blocking* is False executes the scheduled events due to expire soonest
-   (if any) and then return.
+   (if any) and then return the deadline of the next scheduled call in the
+   scheduler (if any).
 
    Either *action* or *delayfunc* can raise an exception.  In either case, the
    scheduler will maintain a consistent state and propagate the exception.  If an
diff --git a/Lib/sched.py b/Lib/sched.py
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -97,7 +97,8 @@
     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.
+        expire soonest (if any) and then return the deadline of the
+        next scheduled call in the scheduler.
 
         When there is a positive delay until the first event, the
         delay function is called and the event is left in the queue;
@@ -129,7 +130,7 @@
                 now = timefunc()
                 if now < time:
                     if not blocking:
-                        return
+                        return time - now
                     delayfunc(time - now)
                 else:
                     event = pop(q)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list