Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 1 | :mod:`select` --- Waiting for I/O completion |
| 2 | ============================================ |
| 3 | |
| 4 | .. module:: select |
| 5 | :synopsis: Wait for I/O completion on multiple streams. |
| 6 | |
| 7 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 8 | This module provides access to the :c:func:`select` and :c:func:`poll` functions |
| 9 | available in most operating systems, :c:func:`epoll` available on Linux 2.5+ and |
| 10 | :c:func:`kqueue` available on most BSD. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 11 | Note that on Windows, it only works for sockets; on other operating systems, |
| 12 | it also works for other file types (in particular, on Unix, it works on pipes). |
| 13 | It cannot be used on regular files to determine whether a file has grown since |
| 14 | it was last read. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 15 | |
| 16 | The module defines the following: |
| 17 | |
| 18 | |
| 19 | .. exception:: error |
| 20 | |
| 21 | The exception raised when an error occurs. The accompanying value is a pair |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 22 | containing the numeric error code from :c:data:`errno` and the corresponding |
| 23 | string, as would be printed by the C function :c:func:`perror`. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 24 | |
| 25 | |
Georg Brandl | 1824415 | 2009-09-02 20:34:52 +0000 | [diff] [blame] | 26 | .. function:: epoll(sizehint=-1) |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 27 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 28 | (Only supported on Linux 2.5.44 and newer.) Returns an edge polling object, |
| 29 | which can be used as Edge or Level Triggered interface for I/O events; see |
| 30 | section :ref:`epoll-objects` below for the methods supported by epolling |
| 31 | objects. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 32 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 33 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 34 | .. function:: poll() |
| 35 | |
| 36 | (Not supported by all operating systems.) Returns a polling object, which |
| 37 | supports registering and unregistering file descriptors, and then polling them |
| 38 | for I/O events; see section :ref:`poll-objects` below for the methods supported |
| 39 | by polling objects. |
| 40 | |
| 41 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 42 | .. function:: kqueue() |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 43 | |
Georg Brandl | e767e04 | 2010-07-14 08:00:22 +0000 | [diff] [blame] | 44 | (Only supported on BSD.) Returns a kernel queue object; see section |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 45 | :ref:`kqueue-objects` below for the methods supported by kqueue objects. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 46 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 47 | |
Benjamin Peterson | 1baf465 | 2009-12-31 03:11:23 +0000 | [diff] [blame] | 48 | .. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0) |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 49 | |
Georg Brandl | e767e04 | 2010-07-14 08:00:22 +0000 | [diff] [blame] | 50 | (Only supported on BSD.) Returns a kernel event object; see section |
| 51 | :ref:`kevent-objects` below for the methods supported by kevent objects. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 52 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 53 | |
Georg Brandl | 734e268 | 2008-08-12 08:18:18 +0000 | [diff] [blame] | 54 | .. function:: select(rlist, wlist, xlist[, timeout]) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 55 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 56 | This is a straightforward interface to the Unix :c:func:`select` system call. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 57 | The first three arguments are sequences of 'waitable objects': either |
| 58 | integers representing file descriptors or objects with a parameterless method |
Georg Brandl | 734e268 | 2008-08-12 08:18:18 +0000 | [diff] [blame] | 59 | named :meth:`fileno` returning such an integer: |
| 60 | |
| 61 | * *rlist*: wait until ready for reading |
| 62 | * *wlist*: wait until ready for writing |
| 63 | * *xlist*: wait for an "exceptional condition" (see the manual page for what |
| 64 | your system considers such a condition) |
| 65 | |
| 66 | Empty sequences are allowed, but acceptance of three empty sequences is |
| 67 | platform-dependent. (It is known to work on Unix but not on Windows.) The |
| 68 | optional *timeout* argument specifies a time-out as a floating point number |
| 69 | in seconds. When the *timeout* argument is omitted the function blocks until |
| 70 | at least one file descriptor is ready. A time-out value of zero specifies a |
| 71 | poll and never blocks. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 72 | |
| 73 | The return value is a triple of lists of objects that are ready: subsets of the |
| 74 | first three arguments. When the time-out is reached without a file descriptor |
| 75 | becoming ready, three empty lists are returned. |
| 76 | |
| 77 | .. index:: |
| 78 | single: socket() (in module socket) |
| 79 | single: popen() (in module os) |
| 80 | |
Antoine Pitrou | 11cb961 | 2010-09-15 11:11:28 +0000 | [diff] [blame] | 81 | Among the acceptable object types in the sequences are Python :term:`file |
| 82 | objects <file object>` (e.g. ``sys.stdin``, or objects returned by |
| 83 | :func:`open` or :func:`os.popen`), socket objects returned by |
| 84 | :func:`socket.socket`. You may also define a :dfn:`wrapper` class yourself, |
| 85 | as long as it has an appropriate :meth:`fileno` method (that really returns |
| 86 | a file descriptor, not just a random integer). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 87 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 88 | .. note:: |
| 89 | |
| 90 | .. index:: single: WinSock |
| 91 | |
Georg Brandl | 734e268 | 2008-08-12 08:18:18 +0000 | [diff] [blame] | 92 | File objects on Windows are not acceptable, but sockets are. On Windows, |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 93 | the underlying :c:func:`select` function is provided by the WinSock |
Georg Brandl | 734e268 | 2008-08-12 08:18:18 +0000 | [diff] [blame] | 94 | library, and does not handle file descriptors that don't originate from |
| 95 | WinSock. |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 96 | |
Antoine Pitrou | cfad97b | 2011-01-25 17:24:57 +0000 | [diff] [blame] | 97 | .. attribute:: PIPE_BUF |
Gregory P. Smith | b970b86 | 2009-07-04 02:28:47 +0000 | [diff] [blame] | 98 | |
Antoine Pitrou | da7be3e | 2011-01-25 16:28:44 +0000 | [diff] [blame] | 99 | The minimum number of bytes which can be written without blocking to a pipe |
| 100 | when the pipe has been reported as ready for writing by :func:`select`, |
| 101 | :func:`poll` or another interface in this module. This doesn't apply |
| 102 | to other kind of file-like objects such as sockets. |
| 103 | |
Amaury Forgeot d'Arc | ace3102 | 2009-07-09 22:44:11 +0000 | [diff] [blame] | 104 | This value is guaranteed by POSIX to be at least 512. Availability: Unix. |
Gregory P. Smith | b970b86 | 2009-07-04 02:28:47 +0000 | [diff] [blame] | 105 | |
Mark Dickinson | 574b1d6 | 2009-10-01 20:20:09 +0000 | [diff] [blame] | 106 | .. versionadded:: 3.2 |
Gregory P. Smith | b970b86 | 2009-07-04 02:28:47 +0000 | [diff] [blame] | 107 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 108 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 109 | .. _epoll-objects: |
| 110 | |
| 111 | Edge and Level Trigger Polling (epoll) Objects |
| 112 | ---------------------------------------------- |
| 113 | |
| 114 | http://linux.die.net/man/4/epoll |
| 115 | |
| 116 | *eventmask* |
| 117 | |
| 118 | +-----------------------+-----------------------------------------------+ |
| 119 | | Constant | Meaning | |
| 120 | +=======================+===============================================+ |
| 121 | | :const:`EPOLLIN` | Available for read | |
| 122 | +-----------------------+-----------------------------------------------+ |
| 123 | | :const:`EPOLLOUT` | Available for write | |
| 124 | +-----------------------+-----------------------------------------------+ |
| 125 | | :const:`EPOLLPRI` | Urgent data for read | |
| 126 | +-----------------------+-----------------------------------------------+ |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 127 | | :const:`EPOLLERR` | Error condition happened on the assoc. fd | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 128 | +-----------------------+-----------------------------------------------+ |
Christian Heimes | 5e69685 | 2008-04-09 08:37:03 +0000 | [diff] [blame] | 129 | | :const:`EPOLLHUP` | Hang up happened on the assoc. fd | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 130 | +-----------------------+-----------------------------------------------+ |
| 131 | | :const:`EPOLLET` | Set Edge Trigger behavior, the default is | |
| 132 | | | Level Trigger behavior | |
| 133 | +-----------------------+-----------------------------------------------+ |
| 134 | | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is | |
| 135 | | | pulled out, the fd is internally disabled | |
| 136 | +-----------------------+-----------------------------------------------+ |
Jean-Paul Calderone | 7f54dce | 2010-07-18 16:30:31 +0000 | [diff] [blame] | 137 | | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 138 | +-----------------------+-----------------------------------------------+ |
Jean-Paul Calderone | 7f54dce | 2010-07-18 16:30:31 +0000 | [diff] [blame] | 139 | | :const:`EPOLLRDBAND` | Priority data band can be read. | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 140 | +-----------------------+-----------------------------------------------+ |
Jean-Paul Calderone | 7f54dce | 2010-07-18 16:30:31 +0000 | [diff] [blame] | 141 | | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 142 | +-----------------------+-----------------------------------------------+ |
Jean-Paul Calderone | 7f54dce | 2010-07-18 16:30:31 +0000 | [diff] [blame] | 143 | | :const:`EPOLLWRBAND` | Priority data may be written. | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 144 | +-----------------------+-----------------------------------------------+ |
Jean-Paul Calderone | 7f54dce | 2010-07-18 16:30:31 +0000 | [diff] [blame] | 145 | | :const:`EPOLLMSG` | Ignored. | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 146 | +-----------------------+-----------------------------------------------+ |
| 147 | |
| 148 | |
| 149 | .. method:: epoll.close() |
| 150 | |
| 151 | Close the control file descriptor of the epoll object. |
| 152 | |
| 153 | |
| 154 | .. method:: epoll.fileno() |
| 155 | |
| 156 | Return the file descriptor number of the control fd. |
| 157 | |
| 158 | |
| 159 | .. method:: epoll.fromfd(fd) |
| 160 | |
| 161 | Create an epoll object from a given file descriptor. |
| 162 | |
| 163 | |
| 164 | .. method:: epoll.register(fd[, eventmask]) |
| 165 | |
| 166 | Register a fd descriptor with the epoll object. |
| 167 | |
R. David Murray | 1855c21 | 2009-05-31 19:44:27 +0000 | [diff] [blame] | 168 | .. note:: |
| 169 | |
| 170 | Registering a file descriptor that's already registered raises an |
| 171 | IOError -- contrary to :ref:`poll-objects`'s register. |
| 172 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 173 | |
| 174 | .. method:: epoll.modify(fd, eventmask) |
| 175 | |
| 176 | Modify a register file descriptor. |
| 177 | |
| 178 | |
| 179 | .. method:: epoll.unregister(fd) |
| 180 | |
| 181 | Remove a registered file descriptor from the epoll object. |
| 182 | |
| 183 | |
| 184 | .. method:: epoll.poll([timeout=-1[, maxevents=-1]]) |
| 185 | |
| 186 | Wait for events. timeout in seconds (float) |
| 187 | |
| 188 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 189 | .. _poll-objects: |
| 190 | |
| 191 | Polling Objects |
| 192 | --------------- |
| 193 | |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 194 | The :c:func:`poll` system call, supported on most Unix systems, provides better |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 195 | scalability for network servers that service many, many clients at the same |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 196 | time. :c:func:`poll` scales better because the system call only requires listing |
| 197 | the file descriptors of interest, while :c:func:`select` builds a bitmap, turns |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 198 | on bits for the fds of interest, and then afterward the whole bitmap has to be |
Georg Brandl | 60203b4 | 2010-10-06 10:11:56 +0000 | [diff] [blame] | 199 | linearly scanned again. :c:func:`select` is O(highest file descriptor), while |
| 200 | :c:func:`poll` is O(number of file descriptors). |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 201 | |
| 202 | |
| 203 | .. method:: poll.register(fd[, eventmask]) |
| 204 | |
| 205 | Register a file descriptor with the polling object. Future calls to the |
| 206 | :meth:`poll` method will then check whether the file descriptor has any pending |
| 207 | I/O events. *fd* can be either an integer, or an object with a :meth:`fileno` |
| 208 | method that returns an integer. File objects implement :meth:`fileno`, so they |
| 209 | can also be used as the argument. |
| 210 | |
| 211 | *eventmask* is an optional bitmask describing the type of events you want to |
| 212 | check for, and can be a combination of the constants :const:`POLLIN`, |
| 213 | :const:`POLLPRI`, and :const:`POLLOUT`, described in the table below. If not |
| 214 | specified, the default value used will check for all 3 types of events. |
| 215 | |
| 216 | +-------------------+------------------------------------------+ |
| 217 | | Constant | Meaning | |
| 218 | +===================+==========================================+ |
| 219 | | :const:`POLLIN` | There is data to read | |
| 220 | +-------------------+------------------------------------------+ |
| 221 | | :const:`POLLPRI` | There is urgent data to read | |
| 222 | +-------------------+------------------------------------------+ |
| 223 | | :const:`POLLOUT` | Ready for output: writing will not block | |
| 224 | +-------------------+------------------------------------------+ |
| 225 | | :const:`POLLERR` | Error condition of some sort | |
| 226 | +-------------------+------------------------------------------+ |
| 227 | | :const:`POLLHUP` | Hung up | |
| 228 | +-------------------+------------------------------------------+ |
| 229 | | :const:`POLLNVAL` | Invalid request: descriptor not open | |
| 230 | +-------------------+------------------------------------------+ |
| 231 | |
| 232 | Registering a file descriptor that's already registered is not an error, and has |
| 233 | the same effect as registering the descriptor exactly once. |
| 234 | |
| 235 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 236 | .. method:: poll.modify(fd, eventmask) |
| 237 | |
| 238 | Modifies an already registered fd. This has the same effect as |
Jean-Paul Calderone | 7f94f39 | 2010-07-18 16:13:27 +0000 | [diff] [blame] | 239 | ``register(fd, eventmask)``. Attempting to modify a file descriptor |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 240 | that was never registered causes an :exc:`IOError` exception with errno |
| 241 | :const:`ENOENT` to be raised. |
| 242 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 243 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 244 | .. method:: poll.unregister(fd) |
| 245 | |
| 246 | Remove a file descriptor being tracked by a polling object. Just like the |
| 247 | :meth:`register` method, *fd* can be an integer or an object with a |
| 248 | :meth:`fileno` method that returns an integer. |
| 249 | |
| 250 | Attempting to remove a file descriptor that was never registered causes a |
| 251 | :exc:`KeyError` exception to be raised. |
| 252 | |
| 253 | |
| 254 | .. method:: poll.poll([timeout]) |
| 255 | |
| 256 | Polls the set of registered file descriptors, and returns a possibly-empty list |
| 257 | containing ``(fd, event)`` 2-tuples for the descriptors that have events or |
| 258 | errors to report. *fd* is the file descriptor, and *event* is a bitmask with |
| 259 | bits set for the reported events for that descriptor --- :const:`POLLIN` for |
| 260 | waiting input, :const:`POLLOUT` to indicate that the descriptor can be written |
| 261 | to, and so forth. An empty list indicates that the call timed out and no file |
| 262 | descriptors had any events to report. If *timeout* is given, it specifies the |
| 263 | length of time in milliseconds which the system will wait for events before |
| 264 | returning. If *timeout* is omitted, negative, or :const:`None`, the call will |
| 265 | block until there is an event for this poll object. |
| 266 | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 267 | |
| 268 | .. _kqueue-objects: |
| 269 | |
| 270 | Kqueue Objects |
| 271 | -------------- |
| 272 | |
| 273 | .. method:: kqueue.close() |
| 274 | |
| 275 | Close the control file descriptor of the kqueue object. |
| 276 | |
| 277 | |
| 278 | .. method:: kqueue.fileno() |
| 279 | |
| 280 | Return the file descriptor number of the control fd. |
| 281 | |
| 282 | |
Benjamin Peterson | 9bc9351 | 2008-09-22 22:10:59 +0000 | [diff] [blame] | 283 | .. method:: kqueue.fromfd(fd) |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 284 | |
| 285 | Create a kqueue object from a given file descriptor. |
| 286 | |
| 287 | |
Benjamin Peterson | 9bc9351 | 2008-09-22 22:10:59 +0000 | [diff] [blame] | 288 | .. method:: kqueue.control(changelist, max_events[, timeout=None]) -> eventlist |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 289 | |
| 290 | Low level interface to kevent |
| 291 | |
| 292 | - changelist must be an iterable of kevent object or None |
| 293 | - max_events must be 0 or a positive integer |
| 294 | - timeout in seconds (floats possible) |
| 295 | |
| 296 | |
| 297 | .. _kevent-objects: |
| 298 | |
| 299 | Kevent Objects |
| 300 | -------------- |
| 301 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 302 | http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2 |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 303 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 304 | .. attribute:: kevent.ident |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 305 | |
| 306 | Value used to identify the event. The interpretation depends on the filter |
| 307 | but it's usually the file descriptor. In the constructor ident can either |
| 308 | be an int or an object with a fileno() function. kevent stores the integer |
| 309 | internally. |
| 310 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 311 | .. attribute:: kevent.filter |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 312 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 313 | Name of the kernel filter. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 314 | |
| 315 | +---------------------------+---------------------------------------------+ |
| 316 | | Constant | Meaning | |
| 317 | +===========================+=============================================+ |
| 318 | | :const:`KQ_FILTER_READ` | Takes a descriptor and returns whenever | |
| 319 | | | there is data available to read | |
| 320 | +---------------------------+---------------------------------------------+ |
| 321 | | :const:`KQ_FILTER_WRITE` | Takes a descriptor and returns whenever | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 322 | | | there is data available to write | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 323 | +---------------------------+---------------------------------------------+ |
| 324 | | :const:`KQ_FILTER_AIO` | AIO requests | |
| 325 | +---------------------------+---------------------------------------------+ |
| 326 | | :const:`KQ_FILTER_VNODE` | Returns when one or more of the requested | |
| 327 | | | events watched in *fflag* occurs | |
| 328 | +---------------------------+---------------------------------------------+ |
| 329 | | :const:`KQ_FILTER_PROC` | Watch for events on a process id | |
| 330 | +---------------------------+---------------------------------------------+ |
| 331 | | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device | |
| 332 | | | [not available on Mac OS X] | |
| 333 | +---------------------------+---------------------------------------------+ |
| 334 | | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is | |
| 335 | | | delivered to the process | |
| 336 | +---------------------------+---------------------------------------------+ |
| 337 | | :const:`KQ_FILTER_TIMER` | Establishes an arbitrary timer | |
| 338 | +---------------------------+---------------------------------------------+ |
| 339 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 340 | .. attribute:: kevent.flags |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 341 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 342 | Filter action. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 343 | |
| 344 | +---------------------------+---------------------------------------------+ |
| 345 | | Constant | Meaning | |
| 346 | +===========================+=============================================+ |
| 347 | | :const:`KQ_EV_ADD` | Adds or modifies an event | |
| 348 | +---------------------------+---------------------------------------------+ |
| 349 | | :const:`KQ_EV_DELETE` | Removes an event from the queue | |
| 350 | +---------------------------+---------------------------------------------+ |
| 351 | | :const:`KQ_EV_ENABLE` | Permitscontrol() to returns the event | |
| 352 | +---------------------------+---------------------------------------------+ |
| 353 | | :const:`KQ_EV_DISABLE` | Disablesevent | |
| 354 | +---------------------------+---------------------------------------------+ |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 355 | | :const:`KQ_EV_ONESHOT` | Removes event after first occurrence | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 356 | +---------------------------+---------------------------------------------+ |
| 357 | | :const:`KQ_EV_CLEAR` | Reset the state after an event is retrieved | |
| 358 | +---------------------------+---------------------------------------------+ |
| 359 | | :const:`KQ_EV_SYSFLAGS` | internal event | |
| 360 | +---------------------------+---------------------------------------------+ |
| 361 | | :const:`KQ_EV_FLAG1` | internal event | |
| 362 | +---------------------------+---------------------------------------------+ |
| 363 | | :const:`KQ_EV_EOF` | Filter specific EOF condition | |
| 364 | +---------------------------+---------------------------------------------+ |
| 365 | | :const:`KQ_EV_ERROR` | See return values | |
| 366 | +---------------------------+---------------------------------------------+ |
| 367 | |
| 368 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 369 | .. attribute:: kevent.fflags |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 370 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 371 | Filter specific flags. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 372 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 373 | :const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags: |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 374 | |
| 375 | +----------------------------+--------------------------------------------+ |
| 376 | | Constant | Meaning | |
| 377 | +============================+============================================+ |
| 378 | | :const:`KQ_NOTE_LOWAT` | low water mark of a socket buffer | |
| 379 | +----------------------------+--------------------------------------------+ |
| 380 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 381 | :const:`KQ_FILTER_VNODE` filter flags: |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 382 | |
| 383 | +----------------------------+--------------------------------------------+ |
| 384 | | Constant | Meaning | |
| 385 | +============================+============================================+ |
| 386 | | :const:`KQ_NOTE_DELETE` | *unlink()* was called | |
| 387 | +----------------------------+--------------------------------------------+ |
Georg Brandl | 2ee470f | 2008-07-16 12:55:28 +0000 | [diff] [blame] | 388 | | :const:`KQ_NOTE_WRITE` | a write occurred | |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 389 | +----------------------------+--------------------------------------------+ |
| 390 | | :const:`KQ_NOTE_EXTEND` | the file was extended | |
| 391 | +----------------------------+--------------------------------------------+ |
| 392 | | :const:`KQ_NOTE_ATTRIB` | an attribute was changed | |
| 393 | +----------------------------+--------------------------------------------+ |
| 394 | | :const:`KQ_NOTE_LINK` | the link count has changed | |
| 395 | +----------------------------+--------------------------------------------+ |
| 396 | | :const:`KQ_NOTE_RENAME` | the file was renamed | |
| 397 | +----------------------------+--------------------------------------------+ |
| 398 | | :const:`KQ_NOTE_REVOKE` | access to the file was revoked | |
| 399 | +----------------------------+--------------------------------------------+ |
| 400 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 401 | :const:`KQ_FILTER_PROC` filter flags: |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 402 | |
| 403 | +----------------------------+--------------------------------------------+ |
| 404 | | Constant | Meaning | |
| 405 | +============================+============================================+ |
| 406 | | :const:`KQ_NOTE_EXIT` | the process has exited | |
| 407 | +----------------------------+--------------------------------------------+ |
| 408 | | :const:`KQ_NOTE_FORK` | the process has called *fork()* | |
| 409 | +----------------------------+--------------------------------------------+ |
| 410 | | :const:`KQ_NOTE_EXEC` | the process has executed a new process | |
| 411 | +----------------------------+--------------------------------------------+ |
| 412 | | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag | |
| 413 | +----------------------------+--------------------------------------------+ |
| 414 | | :const:`KQ_NOTE_PDATAMASK` | internal filter flag | |
| 415 | +----------------------------+--------------------------------------------+ |
| 416 | | :const:`KQ_NOTE_TRACK` | follow a process across *fork()* | |
| 417 | +----------------------------+--------------------------------------------+ |
| 418 | | :const:`KQ_NOTE_CHILD` | returned on the child process for | |
| 419 | | | *NOTE_TRACK* | |
| 420 | +----------------------------+--------------------------------------------+ |
| 421 | | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child | |
| 422 | +----------------------------+--------------------------------------------+ |
| 423 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 424 | :const:`KQ_FILTER_NETDEV` filter flags (not available on Mac OS X): |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 425 | |
| 426 | +----------------------------+--------------------------------------------+ |
| 427 | | Constant | Meaning | |
| 428 | +============================+============================================+ |
| 429 | | :const:`KQ_NOTE_LINKUP` | link is up | |
| 430 | +----------------------------+--------------------------------------------+ |
| 431 | | :const:`KQ_NOTE_LINKDOWN` | link is down | |
| 432 | +----------------------------+--------------------------------------------+ |
| 433 | | :const:`KQ_NOTE_LINKINV` | link state is invalid | |
| 434 | +----------------------------+--------------------------------------------+ |
| 435 | |
| 436 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 437 | .. attribute:: kevent.data |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 438 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 439 | Filter specific data. |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 440 | |
| 441 | |
Christian Heimes | fe337bf | 2008-03-23 21:54:12 +0000 | [diff] [blame] | 442 | .. attribute:: kevent.udata |
Christian Heimes | 4fbc72b | 2008-03-22 00:47:35 +0000 | [diff] [blame] | 443 | |
Georg Brandl | 1b5ab45 | 2009-08-13 07:56:35 +0000 | [diff] [blame] | 444 | User defined value. |