From d81d2d6dbef06c06bf75f4c2c8f1ebde3325cc24 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 13 Aug 2010 06:31:59 -0700 Subject: [PATCH] * Fix IndexError in PollScheduler._next_poll_event() by raising StopIteration instead. * Add an optional timeout parameter to PollScheduler._schedule_wait() (this will be used in a later commit). --- pym/_emerge/PollScheduler.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 4914b286a..704ddc317 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -3,6 +3,7 @@ import logging import select +import time from portage.util import writemsg_level @@ -112,6 +113,8 @@ class PollScheduler(object): """ if not self._poll_event_queue: self._poll(timeout) + if not self._poll_event_queue: + raise StopIteration() return self._poll_event_queue.pop() def _poll_loop(self): @@ -187,7 +190,7 @@ class PollScheduler(object): del self._poll_event_handlers[f] del self._poll_event_handler_ids[reg_id] - def _schedule_wait(self, wait_ids): + def _schedule_wait(self, wait_ids, timeout=None): """ Schedule until wait_id is not longer registered for poll() events. @@ -201,12 +204,18 @@ class PollScheduler(object): if isinstance(wait_ids, int): wait_ids = frozenset([wait_ids]) + start_time = None + if timeout is not None: + start_time = 1000 * time.time() try: while wait_ids.intersection(handler_ids): - f, event = self._next_poll_event() + f, event = self._next_poll_event(timeout=timeout) handler, reg_id = event_handlers[f] handler(f, event) event_handled = True + if timeout is not None: + if 1000 * time.time() - start_time >= timeout: + break except StopIteration: event_handled = True -- 2.26.2