PollScheduler: remove _poll_loop
authorZac Medico <zmedico@gentoo.org>
Thu, 9 Feb 2012 04:04:09 +0000 (20:04 -0800)
committerZac Medico <zmedico@gentoo.org>
Thu, 9 Feb 2012 04:04:09 +0000 (20:04 -0800)
We can use iteration() instead, and _poll_loop's exit behavior doesn't
seem practical to emulate with glib.MainLoop.

pym/_emerge/MetadataRegen.py
pym/_emerge/PollScheduler.py
pym/_emerge/Scheduler.py

index 07fd397dd4c473e09afe0ae86c9653e06bb8f728..1ebc53268399215777f7b8615a126d7408d6f42e 100644 (file)
@@ -33,6 +33,7 @@ class MetadataRegen(PollScheduler):
                self.returncode = os.EX_OK
                self._error_count = 0
                self._running_tasks = set()
+               self._remaining_tasks = True
 
        def _terminate_tasks(self):
                while self._running_tasks:
@@ -87,11 +88,12 @@ class MetadataRegen(PollScheduler):
                from portage.cache.cache_errors import CacheError
                dead_nodes = {}
 
-               while self._schedule():
-                       self.sched_iface.run()
+               self._schedule()
+               while self._remaining_tasks and not self._terminated_tasks:
+                       self.sched_iface.iteration()
 
                while self._jobs:
-                       self.sched_iface.run()
+                       self.sched_iface.iteration()
 
                if self._terminated_tasks:
                        self.returncode = 1
@@ -151,6 +153,7 @@ class MetadataRegen(PollScheduler):
                        try:
                                metadata_process = next(self._process_iter)
                        except StopIteration:
+                               self._remaining_tasks = False
                                return False
 
                        self._jobs += 1
index ab65054112a1541fd16e85ea3b861da6abdb4157..018188bf04c7641783e315ef1bf8be39ff9206fa 100644 (file)
@@ -130,9 +130,8 @@ class EventLoop(object):
 
        def _next_poll_event(self, timeout=None):
                """
-               Since the _schedule_wait() loop is called by event
-               handlers from _poll_loop(), maintain a central event
-               queue for both of them to share events from a single
+               Since iteration() can be called recursively, maintain
+               a central event queue to share events from a single
                poll() call. In order to avoid endless blocking, this
                raises StopIteration if timeout is None and there are
                no file descriptors to poll.
@@ -143,24 +142,6 @@ class EventLoop(object):
                                raise StopIteration()
                return self._poll_event_queue.pop()
 
-       def _poll_loop(self):
-
-               event_handlers = self._poll_event_handlers
-               event_handled = False
-
-               try:
-                       while event_handlers:
-                               f, event = self._next_poll_event()
-                               x = event_handlers[f]
-                               if not x.callback(f, event, *x.args):
-                                       self.source_remove(x.source_id)
-                               event_handled = True
-               except StopIteration:
-                       event_handled = True
-
-               if not event_handled:
-                       raise AssertionError("tight loop")
-
        def iteration(self, *args):
                """
                Like glib.MainContext.iteration(), runs a single iteration.
@@ -376,7 +357,6 @@ class PollScheduler(object):
                        iteration=self._event_loop.iteration,
                        output=self._task_output,
                        register=self._event_loop.io_add_watch,
-                       run=self._event_loop._poll_loop,
                        source_remove=self._event_loop.source_remove,
                        timeout_add=self._event_loop.timeout_add,
                        unregister=self._event_loop.source_remove)
index 6502f71c5af85b2e15d0772eb2152f76d3a70fd2..12f087119e147c445f80ab992b6eaafcec17dd37 100644 (file)
@@ -222,7 +222,6 @@ class Scheduler(PollScheduler):
                        io_add_watch=self._event_loop.io_add_watch,
                        iteration=self._event_loop.iteration,
                        register=self._event_loop.io_add_watch,
-                       schedule=self._event_loop._poll_loop,
                        scheduleSetup=self._schedule_setup,
                        scheduleUnpack=self._schedule_unpack,
                        source_remove=self._event_loop.source_remove,
@@ -1492,14 +1491,12 @@ class Scheduler(PollScheduler):
                if self._opts_no_background.intersection(self.myopts):
                        self._set_max_jobs(1)
 
-               while self._schedule():
-                       self.sched_iface.run()
+               self._schedule()
+               while self._keep_scheduling():
+                       self.sched_iface.iteration()
 
-               while True:
-                       self._schedule()
-                       if not self._is_work_scheduled():
-                               break
-                       self.sched_iface.run()
+               while self._is_work_scheduled():
+                       self.sched_iface.iteration()
 
        def _keep_scheduling(self):
                return bool(not self._terminated_tasks and self._pkg_queue and \