From ef507665cb7b3fe697126f75e794025edf3f03eb Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Mar 2011 20:44:55 -0700 Subject: [PATCH] CompositeTask: handle unstarted terminated tasks --- pym/_emerge/Binpkg.py | 4 ++-- pym/_emerge/CompositeTask.py | 22 ++++++++++++++++++++-- pym/_emerge/EbuildExecuter.py | 4 ++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pym/_emerge/Binpkg.py b/pym/_emerge/Binpkg.py index 65a5ef4a5..b011b001f 100644 --- a/pym/_emerge/Binpkg.py +++ b/pym/_emerge/Binpkg.py @@ -1,4 +1,4 @@ -# Copyright 1999-2010 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from _emerge.EbuildPhase import EbuildPhase @@ -277,7 +277,7 @@ class Binpkg(CompositeTask): settings=settings) setup_phase.addExitListener(self._setup_exit) - self._current_task = setup_phase + self._task_queued(setup_phase) self.scheduler.scheduleSetup(setup_phase) def _setup_exit(self, setup_phase): diff --git a/pym/_emerge/CompositeTask.py b/pym/_emerge/CompositeTask.py index b5e8ce5bb..8e8f0843c 100644 --- a/pym/_emerge/CompositeTask.py +++ b/pym/_emerge/CompositeTask.py @@ -8,13 +8,19 @@ class CompositeTask(AsynchronousTask): __slots__ = ("scheduler",) + ("_current_task",) + _TASK_QUEUED = -1 + def isAlive(self): return self._current_task is not None def cancel(self): self.cancelled = True if self._current_task is not None: - self._current_task.cancel() + 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): @@ -32,7 +38,9 @@ class CompositeTask(AsynchronousTask): prev = None while True: task = self._current_task - if task is None or task is prev: + if task is None or \ + task is self._TASK_QUEUED or \ + task is prev: # don't poll the same task more than once break task.poll() @@ -48,6 +56,10 @@ class CompositeTask(AsynchronousTask): if task is None: # don't wait for the same task more than once break + if task is self._TASK_QUEUED: + self.returncode = 1 + self._current_task = None + break if task is prev: if self.returncode is not None: # This is expected if we're being @@ -123,3 +135,9 @@ class CompositeTask(AsynchronousTask): self._current_task = task task.start() + def _task_queued(self, task): + task.addStartListener(self._task_queued_start_handler) + self._current_task = self._TASK_QUEUED + + def _task_queued_start_handler(self, task): + self._current_task = task diff --git a/pym/_emerge/EbuildExecuter.py b/pym/_emerge/EbuildExecuter.py index b28c73793..f8febd47c 100644 --- a/pym/_emerge/EbuildExecuter.py +++ b/pym/_emerge/EbuildExecuter.py @@ -51,7 +51,7 @@ class EbuildExecuter(CompositeTask): settings=settings) setup_phase.addExitListener(self._setup_exit) - self._current_task = setup_phase + self._task_queued(setup_phase) self.scheduler.scheduleSetup(setup_phase) def _setup_exit(self, setup_phase): @@ -69,7 +69,7 @@ class EbuildExecuter(CompositeTask): # otherwise they can interfere with eachother. unpack_phase.addExitListener(self._unpack_exit) - self._current_task = unpack_phase + self._task_queued(unpack_phase) self.scheduler.scheduleUnpack(unpack_phase) else: -- 2.26.2