From 78ccc379fb914d7604603e08ca4ac9fc30fcfc26 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 11 Feb 2012 11:48:05 -0800 Subject: 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. --- pym/_emerge/QueueScheduler.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'pym') 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 -- cgit v1.2.3-1-g7c22