Scheduler: tweak prefetcher cancellation logic
authorZac Medico <zmedico@gentoo.org>
Thu, 17 Mar 2011 04:50:36 +0000 (21:50 -0700)
committerZac Medico <zmedico@gentoo.org>
Thu, 17 Mar 2011 04:50:36 +0000 (21:50 -0700)
This should prevent "TypeError: an integer is required" raised from
waitpid when trying to cancel a prefetcher that never started.

pym/_emerge/AbstractPollTask.py
pym/_emerge/Binpkg.py
pym/_emerge/EbuildBuild.py
pym/_emerge/Scheduler.py

index 6cbf984b98ca4eb12a3d53261eb2a4add3e0bea9..f7f3a9526d03cc3cf3be647f97d2981948352964 100644 (file)
@@ -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
index b011b001fded8df69213f8d8b5bf5a49ac8092d1..00587451aeb9169d5320232b2a7dabb895408464 100644 (file)
@@ -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. " + \
index afd6399cb081000ebcdffddcd8ad7fd93d51a1fe..98ab24522ee882a93fa1e3313b47a251c2682a78 100644 (file)
@@ -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. " + \
index b961e83c0e98d7e1321c483e0042c046f99a31e5..a1b0ae462db376694ecbaac617e0249c5ad4601d 100644 (file)
@@ -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,