diff options
-rw-r--r-- | pym/_emerge/AsynchronousLock.py | 4 | ||||
-rw-r--r-- | pym/_emerge/AsynchronousTask.py | 15 | ||||
-rw-r--r-- | pym/_emerge/CompositeTask.py | 4 | ||||
-rw-r--r-- | pym/_emerge/FifoIpcDaemon.py | 4 | ||||
-rw-r--r-- | pym/_emerge/PipeReader.py | 4 | ||||
-rw-r--r-- | pym/_emerge/SubProcess.py | 4 | ||||
-rw-r--r-- | pym/_emerge/TaskSequence.py | 3 |
7 files changed, 21 insertions, 17 deletions
diff --git a/pym/_emerge/AsynchronousLock.py b/pym/_emerge/AsynchronousLock.py index c47a20788..6e0a1ac2a 100644 --- a/pym/_emerge/AsynchronousLock.py +++ b/pym/_emerge/AsynchronousLock.py @@ -198,6 +198,10 @@ class _LockProcess(AbstractPollTask): raise AssertionError('lock process failed with returncode %s' \ % (proc.returncode,)) + def _cancel(self): + if self._proc is not None: + self._proc.cancel() + def _wait(self): if self.returncode is not None: return self.returncode diff --git a/pym/_emerge/AsynchronousTask.py b/pym/_emerge/AsynchronousTask.py index 1918b839b..de0080042 100644 --- a/pym/_emerge/AsynchronousTask.py +++ b/pym/_emerge/AsynchronousTask.py @@ -1,4 +1,4 @@ -# Copyright 1999-2009 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from _emerge.SlotObject import SlotObject @@ -45,8 +45,17 @@ class AsynchronousTask(SlotObject): return self.returncode def cancel(self): - self.cancelled = True - self.wait() + if not self.cancelled: + self.cancelled = True + self._cancel() + self.wait() + + def _cancel(self): + """ + Subclasses should implement this, as a template method + to be called by AsynchronousTask.cancel(). + """ + pass def addStartListener(self, f): """ diff --git a/pym/_emerge/CompositeTask.py b/pym/_emerge/CompositeTask.py index 8e8f0843c..edc0768d7 100644 --- a/pym/_emerge/CompositeTask.py +++ b/pym/_emerge/CompositeTask.py @@ -13,15 +13,13 @@ class CompositeTask(AsynchronousTask): def isAlive(self): return self._current_task is not None - def cancel(self): - self.cancelled = True + def _cancel(self): if self._current_task is not None: if self._current_task is self._TASK_QUEUED: self.returncode = 1 self._current_task = None else: self._current_task.cancel() - AsynchronousTask.cancel(self) def _poll(self): """ diff --git a/pym/_emerge/FifoIpcDaemon.py b/pym/_emerge/FifoIpcDaemon.py index c31508a83..a716dac7c 100644 --- a/pym/_emerge/FifoIpcDaemon.py +++ b/pym/_emerge/FifoIpcDaemon.py @@ -43,12 +43,10 @@ class FifoIpcDaemon(AbstractPollTask): def isAlive(self): return self._registered - def cancel(self): + def _cancel(self): if self.returncode is None: self.returncode = 1 - self.cancelled = True self._unregister() - AbstractPollTask.cancel(self) def _wait(self): if self.returncode is not None: diff --git a/pym/_emerge/PipeReader.py b/pym/_emerge/PipeReader.py index 061921a79..375c98f6a 100644 --- a/pym/_emerge/PipeReader.py +++ b/pym/_emerge/PipeReader.py @@ -32,11 +32,9 @@ class PipeReader(AbstractPollTask): def isAlive(self): return self._registered - def cancel(self): + def _cancel(self): if self.returncode is None: self.returncode = 1 - self.cancelled = True - AbstractPollTask.cancel(self) def _wait(self): if self.returncode is not None: diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py index 16c71fe3b..115af803d 100644 --- a/pym/_emerge/SubProcess.py +++ b/pym/_emerge/SubProcess.py @@ -41,15 +41,13 @@ class SubProcess(AbstractPollTask): self.wait() return self.returncode - def cancel(self): + def _cancel(self): if self.isAlive(): try: os.kill(self.pid, signal.SIGTERM) except OSError as e: if e.errno != errno.ESRCH: raise - del e - AbstractPollTask.cancel(self) def isAlive(self): return self.pid is not None and \ diff --git a/pym/_emerge/TaskSequence.py b/pym/_emerge/TaskSequence.py index 7a1bd5a47..1233c99d3 100644 --- a/pym/_emerge/TaskSequence.py +++ b/pym/_emerge/TaskSequence.py @@ -25,9 +25,8 @@ class TaskSequence(CompositeTask): def _start(self): self._start_next_task() - def cancel(self): + def _cancel(self): self._task_queue.clear() - CompositeTask.cancel(self) def _start_next_task(self): self._start_task(self._task_queue.popleft(), |