<--previous | contents | next-->

# kqueue

The kqueue module is an interface to the OpenBSD kernel event notification system.

## Example

The example program below does the following:

- Opens a file named "test" (creating it if it does not exist).
- Creates a EVNode kevent, which monitors for all possible EVNode conditions.
- Creates a new KQueue, and registers the created kevent with it.
- It then enters an infinite loop that simply prints any events recieved.

You can now manipulate the file named "test" to see the kqueue module in action.

    from openbsd.kqueue import *

    f = open("test", "w+")
    ev = EVNode(ident=f, flags=EV_ADD|EV_CLEAR, fflags=
                                                                                                    EVNode.NOTE_WRITE|EVNode.NOTE_DELETE|
                                                                                                    EVNode.NOTE_EXTEND|EVNode.NOTE_ATTRIB|
                                                                                                    EVNode.NOTE_TRUNCATE|EVNode.NOTE_LINK|
                                                                                                    EVNode.NOTE_RENAME|EVNode.NOTE_REVOKE
                            )
    q = KQueue()
    q.kevent(changelist=[ev])
    while 1:
        evs = q.kevent(nevents=1)
        print evs[0]

<--previous | contents | next--> | (12/21/04)

PyOpenbsd v0.1 Manual