summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-02-11 11:48:05 -0800
committerZac Medico <zmedico@gentoo.org>2012-02-11 11:48:05 -0800
commit78ccc379fb914d7604603e08ca4ac9fc30fcfc26 (patch)
tree070cfab38cdf0f1670ba606181bef6c6a58a8d29
parentdcb9fab8463996542d06d29bc383f5933bf0d677 (diff)
downloadportage-78ccc379fb914d7604603e08ca4ac9fc30fcfc26.tar.gz
portage-78ccc379fb914d7604603e08ca4ac9fc30fcfc26.tar.bz2
portage-78ccc379fb914d7604603e08ca4ac9fc30fcfc26.zip
QueueScheduler: timeout compat for GlibEventLoop
Raising StopIteration doesn't work with GlibEventLoop, since it catches all exceptions and logs them. So, just use a boolean expression to terminate the while loop. This depends on commit dcb9fab8463996542d06d29bc383f5933bf0d677 so that IpcDaemonTestCase timeouts work correctly with both EventLoop and GlibEventLoop.
-rw-r--r--pym/_emerge/QueueScheduler.py29
1 files changed, 19 insertions, 10 deletions
diff --git a/pym/_emerge/QueueScheduler.py b/pym/_emerge/QueueScheduler.py
index ba740c11f..5f8cf2674 100644
--- a/pym/_emerge/QueueScheduler.py
+++ b/pym/_emerge/QueueScheduler.py
@@ -38,15 +38,26 @@ class QueueScheduler(PollScheduler):
if timeout is not None:
def timeout_callback():
timeout_callback.timed_out = True
- raise StopIteration()
+ return False
timeout_callback.timed_out = False
timeout_callback.timeout_id = self.sched_iface.timeout_add(
timeout, timeout_callback)
try:
- self._main_loop()
- except StopIteration:
- pass
+ self._schedule()
+
+ while self._keep_scheduling() and \
+ not (timeout_callback is not None and
+ timeout_callback.timed_out):
+ # We don't have any callbacks to trigger _schedule(),
+ # so we have to call it explicitly here.
+ self._schedule()
+ self.sched_iface.iteration()
+
+ while self._is_work_scheduled() and \
+ not (timeout_callback is not None and
+ timeout_callback.timed_out):
+ self.sched_iface.iteration()
finally:
if timeout_callback is not None:
self.sched_iface.unregister(timeout_callback.timeout_id)
@@ -58,7 +69,7 @@ class QueueScheduler(PollScheduler):
False otherwise.
"""
if self._terminated_tasks:
- return False
+ return
while self._can_add_job():
n = self._max_jobs - self._running_job_count()
@@ -66,12 +77,10 @@ class QueueScheduler(PollScheduler):
break
if not self._start_next_job(n):
- return False
+ return
- for q in self._queues:
- if q:
- return True
- return False
+ def _keep_scheduling(self):
+ return not self._terminated_tasks and any(self._queues)
def _running_job_count(self):
job_count = 0