summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/_emerge/AbstractPollTask.py23
-rw-r--r--pym/_emerge/SubProcess.py8
2 files changed, 25 insertions, 6 deletions
diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py
index 13e3c23f9..b4728e7a2 100644
--- a/pym/_emerge/AbstractPollTask.py
+++ b/pym/_emerge/AbstractPollTask.py
@@ -1,10 +1,11 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import array
import errno
import logging
import os
+import time
from portage.util import writemsg_level
from _emerge.AsynchronousTask import AsynchronousTask
@@ -121,3 +122,23 @@ class AbstractPollTask(AsynchronousTask):
self._unregister()
self.wait()
+ def _wait_loop(self, timeout=None):
+
+ if timeout is None:
+ while self._registered:
+ 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
diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py
index c3dc74a91..17a3e8f20 100644
--- a/pym/_emerge/SubProcess.py
+++ b/pym/_emerge/SubProcess.py
@@ -64,8 +64,7 @@ class SubProcess(AbstractPollTask):
if self._registered:
if self.cancelled:
- timeout = self._cancel_timeout
- self.scheduler.schedule(self._reg_id, timeout=timeout)
+ self._wait_loop(timeout=self._cancel_timeout)
if self._registered:
try:
os.kill(self.pid, signal.SIGKILL)
@@ -73,12 +72,11 @@ class SubProcess(AbstractPollTask):
if e.errno != errno.ESRCH:
raise
del e
- self.scheduler.schedule(self._reg_id, timeout=timeout)
+ self._wait_loop(timeout=self._cancel_timeout)
if self._registered:
self._orphan_process_warn()
else:
- while self._registered:
- self.scheduler.iteration()
+ self._wait_loop()
self._unregister()
if self.returncode is not None:
return self.returncode