diff options
author | Zac Medico <zmedico@gentoo.org> | 2023-11-26 17:55:04 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2023-11-28 14:47:53 -0800 |
commit | 9b711229ef913e8772e9a3a1cce744c87ee468cf (patch) | |
tree | f74a2257c406259ad4ffdc615816fb4bc621d767 | |
parent | Increase ignore_priority during topological sort for runtime cycle (diff) | |
download | portage-9b711229ef913e8772e9a3a1cce744c87ee468cf.tar.gz portage-9b711229ef913e8772e9a3a1cce744c87ee468cf.tar.bz2 portage-9b711229ef913e8772e9a3a1cce744c87ee468cf.zip |
Cancel prefetchers that have not started yet
Cancel prefetchers that have not started yet. This will cause the
parallel-fetch SequentialTaskQueue to simply discard them, and
a regular fetcher will be instantiated immediately. This prevents
errors when accessing the pkg_path attribute of BinpkgPrefetcher
instances that have not started yet.
Bug: https://bugs.gentoo.org/918636
Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r-- | lib/_emerge/Binpkg.py | 6 | ||||
-rw-r--r-- | lib/_emerge/CompositeTask.py | 8 | ||||
-rw-r--r-- | lib/_emerge/EbuildBuild.py | 4 | ||||
-rw-r--r-- | lib/_emerge/Scheduler.py | 8 |
4 files changed, 23 insertions, 3 deletions
diff --git a/lib/_emerge/Binpkg.py b/lib/_emerge/Binpkg.py index fac872206..9b1036538 100644 --- a/lib/_emerge/Binpkg.py +++ b/lib/_emerge/Binpkg.py @@ -1,4 +1,4 @@ -# Copyright 1999-2021 Gentoo Authors +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 import functools @@ -110,6 +110,10 @@ class Binpkg(CompositeTask): # use the scheduler and fetcher methods to # synchronize with the fetcher. prefetcher = self.prefetcher + if prefetcher is not None and not prefetcher.isAlive(): + # Cancel it because it hasn't started yet. + prefetcher.cancel() + self.prefetcher = prefetcher = None if prefetcher is None: pass elif prefetcher.isAlive() and prefetcher.poll() is None: diff --git a/lib/_emerge/CompositeTask.py b/lib/_emerge/CompositeTask.py index a0203e71f..50c1b8c5f 100644 --- a/lib/_emerge/CompositeTask.py +++ b/lib/_emerge/CompositeTask.py @@ -1,4 +1,4 @@ -# Copyright 1999-2018 Gentoo Foundation +# Copyright 1999-2023 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 from _emerge.AsynchronousTask import AsynchronousTask @@ -10,6 +10,12 @@ class CompositeTask(AsynchronousTask): _TASK_QUEUED = -1 + def isAlive(self): + """ + Returns True if started and returncode has not been set. + """ + return self.returncode is None and self._current_task is not None + def _cancel(self): if self._current_task is not None: if self._current_task is self._TASK_QUEUED: diff --git a/lib/_emerge/EbuildBuild.py b/lib/_emerge/EbuildBuild.py index 079a67ffb..81cbfdc08 100644 --- a/lib/_emerge/EbuildBuild.py +++ b/lib/_emerge/EbuildBuild.py @@ -96,6 +96,10 @@ class EbuildBuild(CompositeTask): return prefetcher = self.prefetcher + if prefetcher is not None and not prefetcher.isAlive(): + # Cancel it because it hasn't started yet. + prefetcher.cancel() + self.prefetcher = prefetcher = None if prefetcher is None: pass elif prefetcher.isAlive() and prefetcher.poll() is None: diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py index e1179e0f1..66eca4c65 100644 --- a/lib/_emerge/Scheduler.py +++ b/lib/_emerge/Scheduler.py @@ -940,6 +940,10 @@ class Scheduler(PollScheduler): # is consuming time here. if bintree.isremote(x.cpv): fetcher = self._get_prefetcher(x) + if fetcher is not None and not fetcher.isAlive(): + # Cancel it because it hasn't started yet. + fetcher.cancel() + fetcher = None if fetcher is None: fetcher = BinpkgFetcher(pkg=x, scheduler=loop) fetcher.start() @@ -1963,7 +1967,9 @@ class Scheduler(PollScheduler): # CPython 2.7, so it may be possible for CPython to raise KeyError # here as well. prefetcher = None - if prefetcher is not None and not prefetcher.isAlive(): + if prefetcher is not None and ( + prefetcher.cancelled or not prefetcher.isAlive() + ): try: self._task_queues.fetch._task_queue.remove(prefetcher) except ValueError: |