aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2012-02-17 02:20:35 -0800
committerZac Medico <zmedico@gentoo.org>2012-02-17 02:31:07 -0800
commit4a858889202448e93cb43ec2559e9f66c30b09c9 (patch)
treee83a161d2c7a18883e35def4ed59a0e7d0916d5d /pym/portage/util
parentSubProcess._waitpid_cb: fix args for glib compat (diff)
downloadportage-4a858889202448e93cb43ec2559e9f66c30b09c9.tar.gz
portage-4a858889202448e93cb43ec2559e9f66c30b09c9.tar.bz2
portage-4a858889202448e93cb43ec2559e9f66c30b09c9.zip
EventLoop.iteration: run timeouts last
Run timeouts last, in order to minimize latency in termination of iteration loops that they may control.
Diffstat (limited to 'pym/portage/util')
-rw-r--r--pym/portage/util/_eventloop/EventLoop.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/pym/portage/util/_eventloop/EventLoop.py b/pym/portage/util/_eventloop/EventLoop.py
index 808c83d4c..475a4a9c6 100644
--- a/pym/portage/util/_eventloop/EventLoop.py
+++ b/pym/portage/util/_eventloop/EventLoop.py
@@ -130,10 +130,12 @@ class EventLoop(object):
pass
if self._run_timeouts():
events_handled += 1
- if not event_handlers:
- return bool(events_handled)
- else:
- return bool(events_handled)
+
+ # If any timeouts have executed, then return immediately,
+ # in order to minimize latency in termination of iteration
+ # loops that they may control.
+ if events_handled or not event_handlers:
+ return bool(events_handled)
if not event_queue:
@@ -149,17 +151,10 @@ class EventLoop(object):
else:
timeout = 0
- if self._run_timeouts():
- events_handled += 1
-
try:
-
self._poll(timeout=timeout)
except StopIteration:
- # This could happen if there are no IO event handlers
- # after _poll() calls _run_timeouts(), due to them
- # being removed by timeout or idle callbacks. It can
- # also be triggered by EINTR which is caused by signals.
+ # This can be triggered by EINTR which is caused by signals.
pass
# NOTE: IO event handlers may be re-entrant, in case something
@@ -172,6 +167,11 @@ class EventLoop(object):
if not x.callback(f, event, *x.args):
self.source_remove(x.source_id)
+ # Run timeouts last, in order to minimize latency in
+ # termination of iteration loops that they may control.
+ if self._run_timeouts():
+ events_handled += 1
+
return bool(events_handled)
def child_watch_add(self, pid, callback, data=None):