From 48fad6f94aa044c638d5cad8851b4fed8e80309b Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 10 Mar 2011 19:29:57 -0800 Subject: [PATCH] Scheduler: avoid infinite loop after CTRL-C If CTRL-C was received at certain times, it was possible for discarded tasks to be erroneously left in Scheduler._running_tasks, which would cause the main loop to run infinitely. Thanks to David James for reporting this issue and helping to devise a solution. --- pym/_emerge/Scheduler.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index e9c1b6a5e..306c945d7 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -295,6 +295,13 @@ class Scheduler(PollScheduler): def _terminate_tasks(self): self._status_display.quiet = True + # Remove running_tasks that have been added to queues but + # haven't been started yet, since we're going to discard + # them and their start/exit handlers won't be called. + for build in self._task_queues.jobs._task_queue: + self._running_tasks.remove(build.pkg) + for merge in self._task_queues.merge._task_queue: + self._running_tasks.remove(merge.merge.pkg) for q in self._task_queues.values(): q.clear() @@ -1469,7 +1476,13 @@ class Scheduler(PollScheduler): mtimedb.commit() def _build_exit(self, build): - if build.returncode == os.EX_OK: + if build.returncode == os.EX_OK and self._terminated.is_set(): + # We've been interrupted, so we won't + # add this to the merge queue. + self.curval += 1 + self._running_tasks.remove(build.pkg) + self._deallocate_config(build.settings) + elif build.returncode == os.EX_OK: self.curval += 1 merge = PackageMerge(merge=build) if not build.build_opts.buildpkgonly and \ -- 2.26.2