# HG changeset patch # User Nicolas Dumazet # Date 2009-05-21 10:26:15 # Node ID aeaa0bd9dc2439a1ed59848c11042ee67bce53e9 # Parent 228db070bfc4029b310850c66cc23ff0cd67cb3a inotify: process all inotify events in one batch When several inotify events happen, we don't have to process each event separately, calling everytime repowatcher.read_events() to fetch events from the underlying watcher: it is sufficient to call once read_events, to fetch all the events from the watcher. diff --git a/hgext/inotify/server.py b/hgext/inotify/server.py --- a/hgext/inotify/server.py +++ b/hgext/inotify/server.py @@ -500,7 +500,7 @@ class repowatcher(object): evt.fullpath) sys.exit(0) - def handle_pollevent(self): + def handle_pollevents(self, events): if self.ui.debugflag: self.ui.note(_('%s readable: %d bytes\n') % (self.event_time(), self.threshold.readable())) @@ -640,6 +640,10 @@ class server(object): def answer_dbug_query(self): return ['\0'.join(self.repowatcher.debug())] + def handle_pollevents(self, events): + for e in events: + self.handle_pollevent() + def handle_pollevent(self): sock, addr = self.sock.accept() @@ -728,8 +732,13 @@ class master(object): continue raise if events: + by_fd = {} for fd, event in events: - self.table[fd].handle_pollevent() + by_fd.setdefault(fd, []).append(event) + + for fd, events in by_fd.iteritems(): + self.table[fd].handle_pollevents(events) + elif timeobj: timeobj.handle_timeout()