EventLoop.iteration: poll for blocking, not sleep
authorZac Medico <zmedico@gentoo.org>
Fri, 17 Feb 2012 06:29:17 +0000 (22:29 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 17 Feb 2012 06:29:17 +0000 (22:29 -0800)
The effect is be mostly the same, but it's more conistent to use
_do_poll for all blocking, plus it has EINTR handling.

pym/portage/util/_eventloop/EventLoop.py

index 7f171fb8c77310b8232601d181143a1d1636a981..37a971e400b8b9c694dacad4fdf8442848211e9a 100644 (file)
@@ -176,11 +176,14 @@ class EventLoop(object):
                        if not event_handlers:
                                if not events_handled and may_block and \
                                        self._timeout_interval is not None:
-                                       # Sleep so that we don't waste cpu time by looping too
+                                       # Block so that we don't waste cpu time by looping too
                                        # quickly. This makes EventLoop useful for code that needs
                                        # to wait for timeout callbacks regardless of whether or
                                        # not any IO handlers are currently registered.
-                                       time.sleep(self._timeout_interval/1000)
+                                       try:
+                                               self._do_poll(timeout=self._timeout_interval)
+                                       except StopIteration:
+                                               pass
                                        if self._run_timeouts():
                                                events_handled += 1
                                        if not event_handlers: