From: Zac Medico Date: Wed, 8 Feb 2012 05:16:51 +0000 (-0800) Subject: AbstractPollTask: use timeout_add X-Git-Tag: v2.2.0_alpha86~45 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7e38a0253bdc1a25b54f0783c0bb2a72239fdb05;p=portage.git AbstractPollTask: use timeout_add --- diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py index b4728e7a2..922905291 100644 --- a/pym/_emerge/AbstractPollTask.py +++ b/pym/_emerge/AbstractPollTask.py @@ -5,7 +5,6 @@ import array import errno import logging import os -import time from portage.util import writemsg_level from _emerge.AsynchronousTask import AsynchronousTask @@ -129,16 +128,14 @@ class AbstractPollTask(AsynchronousTask): self.scheduler.iteration() return - remaining_timeout = timeout - start_time = time.time() - while self._registered: - self.scheduler.iteration() - 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. - break - remaining_timeout = timeout - 1000 * elapsed_time - if remaining_timeout <= 0: - break + def timeout_cb(): + timeout_cb.timed_out = True + return False + timeout_cb.timed_out = False + timeout_cb.timeout_id = self.scheduler.timeout_add(timeout, timeout_cb) + + try: + while self._registered and not timeout_cb.timed_out: + self.scheduler.iteration() + finally: + self.scheduler.unregister(timeout_cb.timeout_id)