I no longer maintain this software or the associated FreeBSD port (devel/py-kqueue). Work is
going on to locate a new maintainer and update the software to work
with current Python versions. Please don't email me asking to
take over maintainership or offer updates, I've had plenty enough,
I will update this page when the maintainership change is official.
PyKQueue is a Python module that provides an object-oriented interface to the FreeBSD syscalls kqueue(2) and kevent(2).
The kqueue system provides a more robust and less compute-intensive way to monitor system and file events. Instead of slinging huge arrays as needed with select(2), kevent(2) takes a list of KEvents to monitor, and keeps watching them until they're explicitly deleted -- no need to keep passing in the same objects over and over again. This methodology promotes the construction of large asynchronous frameworks, such as the one used in the asyncore Python module.
The current version is 1.2, available at
PyKQueue provides fairly direct access to the kqueue and kevent calls, so reading the kqueue(2) and kevent(2) manpages is a must.
You will want to import all the symbols from the KQueue module to
make accessing the functions easier: use '
from KQueue import *'
in the beginning of your Python program.
The available constructors are:
KQueue()-- Creates a new kernel queue and returns an integer describing it.
kq = KQueue()
KEvent(ident, filter=EVFILT_READ, flags=EV_ADD, fflags=None, data=None, udata=None)-- Creates a new KEvent object, which tracks events on a particular object. Ident is usually a file descriptor but can be any object supported by
kev = KEvent(file.fileno()) # Create a KEvent that triggers when the file object file is ready for reading
The available methods of a KQueue are:
event(kevs, wantEvents, timeout): Wait for an event to trigger, adding the list of KEvents in kevs to the set of filters. Retrieve up to wantEvents events and wait up to timeout milliseconds for an event to show up. Triggered events are returned as a list of KEvents; if the timeout expires, an empty list is returned. Filters that detect an error will return a KEvent with the EV_ERROR flag set.
kevsshould be an empty list if there are no changes to the event watch list.
Please email them to email@example.com.