From: Zac Medico Date: Wed, 8 Feb 2012 04:24:47 +0000 (-0800) Subject: QueueScheduler: use timeout_add X-Git-Tag: v2.2.0_alpha86~48 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=20a5f9cb0c9fec433df7256617bd8fe09892fafa;p=portage.git QueueScheduler: use timeout_add --- diff --git a/pym/_emerge/QueueScheduler.py b/pym/_emerge/QueueScheduler.py index a4ab328e8..91a2831f6 100644 --- a/pym/_emerge/QueueScheduler.py +++ b/pym/_emerge/QueueScheduler.py @@ -36,42 +36,25 @@ class QueueScheduler(PollScheduler): def run(self, timeout=None): - start_time = None - timed_out = False - remaining_timeout = timeout + timeout_id = None if timeout is not None: - start_time = time.time() - - while self._schedule(): - self._schedule_wait(timeout=remaining_timeout) - if timeout is not None: - elapsed_time = time.time() - start_time - if elapsed_time < 0: - # The system clock has changed such that start_time - # is now in the future, so just assume that the - # timeout has already elapsed. - timed_out = True - break - remaining_timeout = timeout - 1000 * elapsed_time - if remaining_timeout <= 0: - timed_out = True - break - - if timeout is None or not timed_out: + def timeout_callback(): + raise StopIteration() + timeout_id = self._timeout_add(timeout, timeout_callback) + + try: + + while self._schedule(): + self._iteration() + while self._running_job_count(): - self._schedule_wait(timeout=remaining_timeout) - if timeout is not None: - elapsed_time = time.time() - start_time - if elapsed_time < 0: - # The system clock has changed such that start_time - # is now in the future, so just assume that the - # timeout has already elapsed. - timed_out = True - break - remaining_timeout = timeout - 1000 * elapsed_time - if remaining_timeout <= 0: - timed_out = True - break + self._iteration() + + except StopIteration: + pass + + if timeout_id is not None: + self._unregister(timeout_id) def _schedule_tasks(self): """