QueueScheduler: tweak timeout handling
authorZac Medico <zmedico@gentoo.org>
Wed, 8 Feb 2012 05:03:32 +0000 (21:03 -0800)
committerZac Medico <zmedico@gentoo.org>
Wed, 8 Feb 2012 06:08:45 +0000 (22:08 -0800)
pym/_emerge/QueueScheduler.py

index 91a2831f637bf176f3cbb3bf3cce0eead6a3dc8d..e115ba1aad726eb4c6249ea63856286ad9305b33 100644 (file)
@@ -1,8 +1,6 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-import time
-
 from _emerge.PollScheduler import PollScheduler
 
 class QueueScheduler(PollScheduler):
@@ -36,25 +34,28 @@ class QueueScheduler(PollScheduler):
 
        def run(self, timeout=None):
 
-               timeout_id = None
+               timeout_callback = None
                if timeout is not None:
                        def timeout_callback():
-                               raise StopIteration()
-                       timeout_id = self._timeout_add(timeout, timeout_callback)
+                               timeout_callback.timed_out = True
+                               return False
+                       timeout_callback.timed_out = False
+                       timeout_callback.timeout_id = self._timeout_add(
+                               timeout, timeout_callback)
 
                try:
 
-                       while self._schedule():
+                       while not (timeout_callback is not None and
+                               timeout_callback.timed_out) and self._schedule():
                                self._iteration()
 
-                       while self._running_job_count():
+                       while not (timeout_callback is not None and
+                               timeout_callback.timed_out) and self._running_job_count():
                                self._iteration()
 
-               except StopIteration:
-                       pass
-
-               if timeout_id is not None:
-                       self._unregister(timeout_id)
+               finally:
+                       if timeout_callback is not None:
+                               self._unregister(timeout_callback.timeout_id)
 
        def _schedule_tasks(self):
                """