Mercurial > hg
comparison hgext/inotify/server.py @ 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 |
comparison
equal
deleted
inserted
replaced
8792:3e23b1d20837 | 8793:9d0c521bce0e |
---|---|
155 self.timeout = timeout | 155 self.timeout = timeout |
156 | 156 |
157 def unregister(self): | 157 def unregister(self): |
158 pollable.poll.unregister(self) | 158 pollable.poll.unregister(self) |
159 self.registered = False | 159 self.registered = False |
160 | |
161 @classmethod | |
162 def run(cls): | |
163 while True: | |
164 timeout = None | |
165 timeobj = None | |
166 for obj in cls.instances.itervalues(): | |
167 if obj.timeout is not None and (timeout is None or obj.timeout < timeout): | |
168 timeout, timeobj = obj.timeout, obj | |
169 try: | |
170 events = cls.poll.poll(timeout) | |
171 except select.error, err: | |
172 if err[0] == errno.EINTR: | |
173 continue | |
174 raise | |
175 if events: | |
176 by_fd = {} | |
177 for fd, event in events: | |
178 by_fd.setdefault(fd, []).append(event) | |
179 | |
180 for fd, events in by_fd.iteritems(): | |
181 cls.instances[fd].handle_pollevents(events) | |
182 | |
183 elif timeobj: | |
184 timeobj.handle_timeout() | |
160 | 185 |
161 def eventaction(code): | 186 def eventaction(code): |
162 """ | 187 """ |
163 Decorator to help handle events in repowatcher | 188 Decorator to help handle events in repowatcher |
164 """ | 189 """ |
744 def run(self): | 769 def run(self): |
745 self.repowatcher.setup() | 770 self.repowatcher.setup() |
746 self.ui.note(_('finished setup\n')) | 771 self.ui.note(_('finished setup\n')) |
747 if os.getenv('TIME_STARTUP'): | 772 if os.getenv('TIME_STARTUP'): |
748 sys.exit(0) | 773 sys.exit(0) |
749 while True: | 774 pollable.run() |
750 timeout = None | |
751 timeobj = None | |
752 for obj in pollable.instances.itervalues(): | |
753 if obj.timeout is not None and (timeout is None or obj.timeout < timeout): | |
754 timeout, timeobj = obj.timeout, obj | |
755 try: | |
756 if self.ui.debugflag: | |
757 if timeout is None: | |
758 self.ui.note(_('polling: no timeout\n')) | |
759 else: | |
760 self.ui.note(_('polling: %sms timeout\n') % timeout) | |
761 events = pollable.poll.poll(timeout) | |
762 except select.error, err: | |
763 if err[0] == errno.EINTR: | |
764 continue | |
765 raise | |
766 if events: | |
767 by_fd = {} | |
768 for fd, event in events: | |
769 by_fd.setdefault(fd, []).append(event) | |
770 | |
771 for fd, events in by_fd.iteritems(): | |
772 pollable.instances[fd].handle_pollevents(events) | |
773 | |
774 elif timeobj: | |
775 timeobj.handle_timeout() | |
776 | 775 |
777 def start(ui, repo): | 776 def start(ui, repo): |
778 def closefds(ignore): | 777 def closefds(ignore): |
779 # (from python bug #1177468) | 778 # (from python bug #1177468) |
780 # close all inherited file descriptors | 779 # close all inherited file descriptors |