From f7b5b5f0da301d8f5c5585c21db238e28546c70f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 16 Mar 2011 21:50:36 -0700 Subject: [PATCH] Scheduler: tweak prefetcher cancellation logic This should prevent "TypeError: an integer is required" raised from waitpid when trying to cancel a prefetcher that never started. --- pym/_emerge/AbstractPollTask.py | 3 +++ pym/_emerge/Binpkg.py | 5 ++--- pym/_emerge/EbuildBuild.py | 5 ++--- pym/_emerge/Scheduler.py | 10 +++++++++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py index 6cbf984b9..f7f3a9526 100644 --- a/pym/_emerge/AbstractPollTask.py +++ b/pym/_emerge/AbstractPollTask.py @@ -17,6 +17,9 @@ class AbstractPollTask(AsynchronousTask): _registered_events = PollConstants.POLLIN | PollConstants.POLLHUP | \ _exceptional_events + def isAlive(self): + return bool(self._registered) + def _read_buf(self, f, event): """ | POLLIN | RETURN diff --git a/pym/_emerge/Binpkg.py b/pym/_emerge/Binpkg.py index b011b001f..00587451a 100644 --- a/pym/_emerge/Binpkg.py +++ b/pym/_emerge/Binpkg.py @@ -77,9 +77,8 @@ class Binpkg(CompositeTask): prefetcher = self.prefetcher if prefetcher is None: pass - elif not prefetcher.isAlive(): - prefetcher.cancel() - elif prefetcher.poll() is None: + elif prefetcher.isAlive() and \ + prefetcher.poll() is None: waiting_msg = ("Fetching '%s' " + \ "in the background. " + \ diff --git a/pym/_emerge/EbuildBuild.py b/pym/_emerge/EbuildBuild.py index afd6399cb..98ab24522 100644 --- a/pym/_emerge/EbuildBuild.py +++ b/pym/_emerge/EbuildBuild.py @@ -65,9 +65,8 @@ class EbuildBuild(CompositeTask): prefetcher = self.prefetcher if prefetcher is None: pass - elif not prefetcher.isAlive(): - prefetcher.cancel() - elif prefetcher.poll() is None: + elif prefetcher.isAlive() and \ + prefetcher.poll() is None: waiting_msg = "Fetching files " + \ "in the background. " + \ diff --git a/pym/_emerge/Scheduler.py b/pym/_emerge/Scheduler.py index b961e83c0..a1b0ae462 100644 --- a/pym/_emerge/Scheduler.py +++ b/pym/_emerge/Scheduler.py @@ -1821,6 +1821,14 @@ class Scheduler(PollScheduler): "installed", pkg.root_config, installed=True, operation="uninstall") + prefetcher = self._prefetchers.pop(pkg, None) + if prefetcher is not None and not prefetcher.isAlive(): + try: + self._task_queues.fetch._task_queue.remove(prefetcher) + except ValueError: + pass + prefetcher = None + task = MergeListItem(args_set=self._args_set, background=self._background, binpkg_opts=self._binpkg_opts, build_opts=self._build_opts, @@ -1830,7 +1838,7 @@ class Scheduler(PollScheduler): find_blockers=self._find_blockers(pkg), logger=self._logger, mtimedb=self._mtimedb, pkg=pkg, pkg_count=self._pkg_count.copy(), pkg_to_replace=pkg_to_replace, - prefetcher=self._prefetchers.get(pkg), + prefetcher=prefetcher, scheduler=self._sched_iface, settings=self._allocate_config(pkg.root), statusMessage=self._status_msg, -- 2.26.2