CompositeTask: handle unstarted terminated tasks
authorZac Medico <zmedico@gentoo.org>
Thu, 17 Mar 2011 03:44:55 +0000 (20:44 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 17 Mar 2011 03:44:55 +0000 (20:44 -0700)
pym/_emerge/Binpkg.py
pym/_emerge/CompositeTask.py
pym/_emerge/EbuildExecuter.py

index 65a5ef4a51e4a7d878143a99bc61f8a51034031e..b011b001fded8df69213f8d8b5bf5a49ac8092d1 100644 (file)
@@ -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):
index b5e8ce5bbf2db174db92e7b96814f1cb6da84d3a..8e8f0843c8522e118352e968484e310eb08f3a91 100644 (file)
@@ -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
index b28c7379370e8b0b78c77ddc22be6ebd354a604f..f8febd47cc52116c5f760429066c936f7ae4695d 100644 (file)
@@ -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: