From b696337bf20fdc539ce7721df7a4b42b35999705 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 20 Aug 2012 20:29:04 -0700 Subject: [PATCH] PollScheduler: use timeout for loadavg checks This ensures that the code from commit fe03b5fd790fc09bd6594c55bb174e80aaac1e5a behaves correctly even when there are no poll events arriving for a long time (which might happen if the running builds don't produce output for a long time). --- pym/_emerge/PollScheduler.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pym/_emerge/PollScheduler.py b/pym/_emerge/PollScheduler.py index 5103e31d6..808fa6e1f 100644 --- a/pym/_emerge/PollScheduler.py +++ b/pym/_emerge/PollScheduler.py @@ -20,6 +20,9 @@ from _emerge.getloadavg import getloadavg class PollScheduler(object): + # max time between loadavg checks (milliseconds) + _loadavg_latency = 30000 + class _sched_iface_class(SlotObject): __slots__ = ("IO_ERR", "IO_HUP", "IO_IN", "IO_NVAL", "IO_OUT", "IO_PRI", "child_watch_add", @@ -147,23 +150,24 @@ class PollScheduler(object): def _main_loop(self): term_check_id = self.sched_iface.idle_add(self._termination_check) + loadavg_check_id = None + if self._max_load is not None: + # We have to schedule periodically, in case the load + # average has changed since the last call. + loadavg_check_id = self.sched_iface.timeout_add( + self._loadavg_latency, self._schedule) + try: # Populate initial event sources. Unless we're scheduling # based on load average, we only need to do this once # here, since it can be called during the loop from within # event handlers. self._schedule() - max_load = self._max_load # Loop while there are jobs to be scheduled. while self._keep_scheduling(): self.sched_iface.iteration() - if max_load is not None: - # We have to schedule periodically, in case the load - # average has changed since the last call. - self._schedule() - # Clean shutdown of previously scheduled jobs. In the # case of termination, this allows for basic cleanup # such as flushing of buffered output to logs. @@ -171,6 +175,8 @@ class PollScheduler(object): self.sched_iface.iteration() finally: self.sched_iface.source_remove(term_check_id) + if loadavg_check_id is not None: + self.sched_iface.source_remove(loadavg_check_id) def _is_work_scheduled(self): return bool(self._running_job_count()) -- 2.26.2