Commits

YAMAMOTO Takashi  committed 211a0a3

hubs: kqueue: enable kqueue hub; avoid modifying read-only attributes

  • Participants
  • Parent commits 1084fbc

Comments (0)

Files changed (2)

File eventlet/hubs/__init__.py

         import eventlet.hubs.epolls
         return eventlet.hubs.epolls
     except ImportError:
-        if hasattr(select, 'poll'):
-            import eventlet.hubs.poll
-            return eventlet.hubs.poll
-        else:
-            import eventlet.hubs.selects
-            return eventlet.hubs.selects
+        try:
+            import eventlet.hubs.kqueue
+            return eventlet.hubs.kqueue
+        except ImportError:
+            if hasattr(select, 'poll'):
+                import eventlet.hubs.poll
+                return eventlet.hubs.poll
+            else:
+                import eventlet.hubs.selects
+                return eventlet.hubs.selects
 
 
 def use_hub(mod=None):

File eventlet/hubs/kqueue.py

             self.kqueue.control([event], 0, 0)
         return listener
 
+    def _delete_events(self, events):
+        del_events = map(lambda e: select.kevent(e.ident, e.filter,
+                         select.KQ_EV_DELETE), events)
+        self.kqueue.control(del_events, 0, 0)
+
     def remove(self, listener):
         super(Hub, self).remove(listener)
         evtype = listener.evtype
         fileno = listener.fileno
         if not self.listeners[evtype].get(fileno):
             event = self._events[fileno].pop(evtype)
-            event.flags = select.KQ_EV_DELETE
             try:
-                self.kqueue.control([event], 0, 0)
+                self._delete_events([event])
             except OSError, e:
                 pass
 
         super(Hub, self).remove_descriptor(fileno)
         try:
             events = self._events.pop(fileno).values()
-            for event in events:
-                event.flags = select.KQ_EV_DELETE
-            self.kqueue.control(events, 0, 0)
+            self._delete_events(events)
         except KeyError, e:
             pass
         except OSError, e: