[Python-Dev] epoll() and kqueue wrapper for the select module

Giampaolo Rodola' gnewsg at gmail.com
Fri Dec 21 15:42:53 CET 2007


This makes me very happy.
I could try to work on integrating this stuff in asyncore, if someone
finds this of some interest.

On 20 Dic, 18:08, Christian Heimes <li... at cheimes.de> wrote:
> Linux Kernel 2.6+ and BSD (including Mac OS X) have two I/O event
> notification systems similar but superior to select() and poll(). From
> the manuals:
>
> kqueue, kevent -- kernel event notification mechanism
>
> The kqueue() system call provides a generic method of notifying the user
> when an event happens or a condition holds, based on the results of
> small pieces of kernel code termed filters.  A kevent is identified by
> the (ident, filter) pair; there may only be one unique kevent per kqueue.
>
> epoll - I/O event notification facility
>
> epoll  is  a variant of poll(2) that can be used either as an
> edge-triggered or a level-triggered interface and scales well to large
> numbers of watched file descriptors.
>
> I've written wrappers for both mechanisms. Both wrappers are inspired
> from Twisted and select.poll()'s API. The interface is more Pythonic
> than the available wrappers and it reduced the burden on the user. The
> users don't have to deal with low level control file descriptors and the
> fd is closed automatically when the object is collected.
>
> epoll interface
>
> >>> ep = select.epoll(1)
> >>> ep.register(fd, select.EPOLL_IN | select.EPOLL_OUT)
> >>> ep.modify(fd, select.EPOLL_OUT)
> >>> events = ep.wait(1, 1000)
> >>> ep.unregister(fd)
>
> kqueue interface
>
> The kqueue interface is more low level than the epoll interface. It has
> too many options.>>> kq = select.kqueue()
> >>> ev = [select.kevent(fd, select.KQ_FILTER_WRITE,
>
>                   select.KQ_EV_ONESHOT | select.KQ_EV_ADD)]
>
> >>> kq.control(ev, 0, 0)
> >>> events = kq.control([], 1, None)
>
> I already talked to some Twisted guys and they really like it. A patch
> is available athttp://bugs.python.org/issue1657. The code needs more
> unit tests and documentation updates.
>
> Christian
>
> _______________________________________________
> Python-Dev mailing list
> Python-... at python.orghttp://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:http://mail.python.org/mailman/options/python-dev/python-dev2-garchiv...


More information about the Python-Dev mailing list