diff options
-rw-r--r-- | pym/_emerge/MetadataRegen.py | 10 | ||||
-rw-r--r-- | pym/_emerge/PollScheduler.py | 22 | ||||
-rw-r--r-- | pym/_emerge/QueueScheduler.py | 10 | ||||
-rw-r--r-- | pym/_emerge/Scheduler.py | 15 |
4 files changed, 30 insertions, 27 deletions
diff --git a/pym/_emerge/MetadataRegen.py b/pym/_emerge/MetadataRegen.py index 1ebc53268..340400119 100644 --- a/pym/_emerge/MetadataRegen.py +++ b/pym/_emerge/MetadataRegen.py @@ -82,18 +82,16 @@ class MetadataRegen(PollScheduler): portdb=portdb, repo_path=repo_path, settings=portdb.doebuild_settings) + def _keep_scheduling(self): + return self._remaining_tasks and not self._terminated_tasks + def run(self): portdb = self._portdb from portage.cache.cache_errors import CacheError dead_nodes = {} - self._schedule() - while self._remaining_tasks and not self._terminated_tasks: - self.sched_iface.iteration() - - while self._jobs: - self.sched_iface.iteration() + self._main_loop() if self._terminated_tasks: self.returncode = 1 diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index eafb8a237..3b3ef67df 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -109,6 +109,28 @@ class PollScheduler(object): finally: self._scheduling = False + def _main_loop(self): + # Populate initial event sources. We only need to do + # this once here, since it can be called during the + # loop from within event handlers. + self._schedule() + + # Loop while there are jobs to be scheduled. + while self._keep_scheduling(): + self.sched_iface.iteration() + + # Clean shutdown of previously scheduled jobs. In the + # case of termination, this allows for basic cleanup + # such as flushing of buffered output to logs. + while self._is_work_scheduled(): + self.sched_iface.iteration() + + def _keep_scheduling(self): + return False + + def _is_work_scheduled(self): + return bool(self._running_job_count()) + def _running_job_count(self): return self._jobs diff --git a/pym/_emerge/QueueScheduler.py b/pym/_emerge/QueueScheduler.py index e34758a85..ba740c11f 100644 --- a/pym/_emerge/QueueScheduler.py +++ b/pym/_emerge/QueueScheduler.py @@ -44,15 +44,7 @@ class QueueScheduler(PollScheduler): timeout, timeout_callback) try: - - while not (timeout_callback is not None and - timeout_callback.timed_out) and self._schedule(): - self.sched_iface.iteration() - - while not (timeout_callback is not None and - timeout_callback.timed_out) and self._running_job_count(): - self.sched_iface.iteration() - + self._main_loop() except StopIteration: pass finally: diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index 100d89d1c..66d76b1e0 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1347,6 +1347,9 @@ class Scheduler(PollScheduler): def _merge(self): + if self._opts_no_background.intersection(self.myopts): + self._set_max_jobs(1) + self._add_prefetchers() self._add_packages() failed_pkgs = self._failed_pkgs @@ -1493,18 +1496,6 @@ class Scheduler(PollScheduler): def _deallocate_config(self, settings): self._config_pool[settings['EROOT']].append(settings) - def _main_loop(self): - - if self._opts_no_background.intersection(self.myopts): - self._set_max_jobs(1) - - self._schedule() - while self._keep_scheduling(): - self.sched_iface.iteration() - - while self._is_work_scheduled(): - self.sched_iface.iteration() - def _keep_scheduling(self): return bool(not self._terminated_tasks and self._pkg_queue and \ not (self._failed_pkgs and not self._build_opts.fetchonly)) |