[ostree] mainloop: Don't create poll until we need to
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] mainloop: Don't create poll until we need to
- Date: Tue, 6 Mar 2012 17:01:32 +0000 (UTC)
commit e4849ebd2bf4dce95eabc0e7a33699e1665f6b06
Author: Colin Walters <walters verbum org>
Date: Tue Mar 6 08:10:33 2012 -0500
mainloop: Don't create poll until we need to
This slightly optimizes the case where we speculatively create a
Mainloop we might not use.
src/ostbuild/pyostbuild/mainloop.py | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
---
diff --git a/src/ostbuild/pyostbuild/mainloop.py b/src/ostbuild/pyostbuild/mainloop.py
index d56010b..40a67be 100644
--- a/src/ostbuild/pyostbuild/mainloop.py
+++ b/src/ostbuild/pyostbuild/mainloop.py
@@ -25,7 +25,7 @@ class Mainloop(object):
DEFAULT = None
def __init__(self):
self._running = True
- self.poll = select.poll()
+ self.poll = None
self._timeouts = []
self._pid_watches = {}
self._fd_callbacks = {}
@@ -38,7 +38,12 @@ class Mainloop(object):
return cls.DEFAULT
raise NotImplementedError("Unknown context %r" % (context, ))
+ def _ensure_poll(self):
+ if self.poll is None:
+ self.poll = select.poll()
+
def watch_fd(self, fd, callback):
+ self._ensure_poll()
self.poll.register(fd)
self._fd_callbacks[fd] = callback
@@ -63,6 +68,7 @@ class Mainloop(object):
if (min_timeout is None) or (ms < min_timeout):
min_timeout = ms
origtime = time.time() * 1000
+ self._ensure_poll()
fds = self.poll.poll(min_timeout)
for fd in fds:
self._fd_callbacks[fd]()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]