Mercurial > hg-stable
changeset 8793:9d0c521bce0e
inotify: put the "while True: poll()" loop in pollable class
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Thu, 21 May 2009 23:51:54 +0900 |
parents | 3e23b1d20837 |
children | 1c610db4a897 |
files | hgext/inotify/server.py |
diffstat | 1 files changed, 26 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/inotify/server.py Thu May 21 20:15:00 2009 +0900 +++ b/hgext/inotify/server.py Thu May 21 23:51:54 2009 +0900 @@ -158,6 +158,31 @@ pollable.poll.unregister(self) self.registered = False + @classmethod + def run(cls): + while True: + timeout = None + timeobj = None + for obj in cls.instances.itervalues(): + if obj.timeout is not None and (timeout is None or obj.timeout < timeout): + timeout, timeobj = obj.timeout, obj + try: + events = cls.poll.poll(timeout) + except select.error, err: + if err[0] == errno.EINTR: + continue + raise + if events: + by_fd = {} + for fd, event in events: + by_fd.setdefault(fd, []).append(event) + + for fd, events in by_fd.iteritems(): + cls.instances[fd].handle_pollevents(events) + + elif timeobj: + timeobj.handle_timeout() + def eventaction(code): """ Decorator to help handle events in repowatcher @@ -746,33 +771,7 @@ self.ui.note(_('finished setup\n')) if os.getenv('TIME_STARTUP'): sys.exit(0) - while True: - timeout = None - timeobj = None - for obj in pollable.instances.itervalues(): - if obj.timeout is not None and (timeout is None or obj.timeout < timeout): - timeout, timeobj = obj.timeout, obj - try: - if self.ui.debugflag: - if timeout is None: - self.ui.note(_('polling: no timeout\n')) - else: - self.ui.note(_('polling: %sms timeout\n') % timeout) - events = pollable.poll.poll(timeout) - except select.error, err: - if err[0] == errno.EINTR: - continue - raise - if events: - by_fd = {} - for fd, event in events: - by_fd.setdefault(fd, []).append(event) - - for fd, events in by_fd.iteritems(): - pollable.instances[fd].handle_pollevents(events) - - elif timeobj: - timeobj.handle_timeout() + pollable.run() def start(ui, repo): def closefds(ignore):