CompositeTask: fix _wait for TASK_QUEUED
authorZac Medico <zmedico@gentoo.org>
Fri, 18 Mar 2011 21:05:07 +0000 (14:05 -0700)
committerZac Medico <zmedico@gentoo.org>
Fri, 18 Mar 2011 21:05:07 +0000 (14:05 -0700)
Though this case might never have been triggered, the logic was broken
for cases in which self.cancelled was false and a task was queued. In
this case we need to call back into the scheduler until the queued task
is started or we are cancelled, whichever comes first.

pym/_emerge/CompositeTask.py

index edc0768d73c1f144167b7f656ce32f243d20bf12..644a69bb2eccc1d30f779fffb3fd7d87e4d359c2 100644 (file)
@@ -55,9 +55,21 @@ class CompositeTask(AsynchronousTask):
                                # 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 self.cancelled:
+                                       self.returncode = 1
+                                       self._current_task = None
+                                       break
+                               else:
+                                       self.scheduler.schedule(condition=self._task_queued_wait)
+                                       if self.returncode is not None:
+                                               break
+                                       elif self.cancelled:
+                                               self.returncode = 1
+                                               self._current_task = None
+                                               break
+                                       else:
+                                               # try this again with new _current_task value
+                                               continue
                        if task is prev:
                                if self.returncode is not None:
                                        # This is expected if we're being
@@ -139,3 +151,7 @@ class CompositeTask(AsynchronousTask):
 
        def _task_queued_start_handler(self, task):
                self._current_task = task
+
+       def _task_queued_wait(self):
+               return self._current_task is not self._TASK_QUEUED or \
+                       self.cancelled or self.returncode is not None