blob: a5e0c133e95a54f2f175cadd034bee553e2c1f49 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001: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 Brandl60203b42010-10-06 10:11:56 +00008This module provides access to the :c:func:`select` and :c:func:`poll` functions
Jesus Cead8b9ae62011-11-14 19:07:41 +01009available in most operating systems, :c:func:`devpoll` available on
10Solaris and derivatives, :c:func:`epoll` available on Linux 2.5+ and
Georg Brandl60203b42010-10-06 10:11:56 +000011:c:func:`kqueue` available on most BSD.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000012Note that on Windows, it only works for sockets; on other operating systems,
13it also works for other file types (in particular, on Unix, it works on pipes).
14It cannot be used on regular files to determine whether a file has grown since
15it was last read.
Georg Brandl116aa622007-08-15 14:28:22 +000016
Victor Stinner73821c42013-09-04 20:40:13 +020017.. note::
18
19 The :mod:`selectors` module allows high-level and efficient I/O
20 multiplexing, built upon the :mod:`select` module primitives. Users are
21 encouraged to use the :mod:`selectors` module instead, unless they want
22 precise control over the OS-level primitives used.
23
24
Georg Brandl116aa622007-08-15 14:28:22 +000025The module defines the following:
26
27
28.. exception:: error
29
Antoine Pitrou9b7fcf82011-10-12 16:23:02 +020030 A deprecated alias of :exc:`OSError`.
31
32 .. versionchanged:: 3.3
33 Following :pep:`3151`, this class was made an alias of :exc:`OSError`.
Georg Brandl116aa622007-08-15 14:28:22 +000034
35
Jesus Cead8b9ae62011-11-14 19:07:41 +010036.. function:: devpoll()
Jesus Ceaf450c1b2011-11-15 05:42:59 +010037
Jesus Cead8b9ae62011-11-14 19:07:41 +010038 (Only supported on Solaris and derivatives.) Returns a ``/dev/poll``
39 polling object; see section :ref:`devpoll-objects` below for the
40 methods supported by devpoll objects.
41
42 :c:func:`devpoll` objects are linked to the number of file
43 descriptors allowed at the time of instantiation. If your program
44 reduces this value, :c:func:`devpoll` will fail. If your program
Jesus Ceaf450c1b2011-11-15 05:42:59 +010045 increases this value, :c:func:`devpoll` may return an
Jesus Cead8b9ae62011-11-14 19:07:41 +010046 incomplete list of active file descriptors.
47
Victor Stinnerdaf45552013-08-28 00:53:59 +020048 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
49
Jesus Cead8b9ae62011-11-14 19:07:41 +010050 .. versionadded:: 3.3
51
Victor Stinnerdaf45552013-08-28 00:53:59 +020052 .. versionchanged:: 3.4
53 The new file descriptor is now non-inheritable.
54
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060055.. function:: epoll(sizehint=-1, flags=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +000056
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060057 (Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
58 which can be used as Edge or Level Triggered interface for I/O
59 events. *sizehint* is deprecated and completely ignored. *flags* can be set
60 to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed
R David Murray2bc930f2013-12-31 11:17:21 -050061 automatically when :func:`os.execve` is called.
62
63 See the :ref:`epoll-objects` section below for the methods supported by
64 epolling objects.
65
66 ``epoll`` objects support the context management protocol: when used in a
67 :keyword:`with` statement, the new file descriptor is automatically closed
68 at the end of the block.
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060069
Victor Stinnerdaf45552013-08-28 00:53:59 +020070 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
71
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060072 .. versionchanged:: 3.3
Benjamin Peterson2fb9ae92011-12-27 15:15:41 -060073 Added the *flags* parameter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000074
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010075 .. versionchanged:: 3.4
76 Support for the :keyword:`with` statement was added.
Victor Stinnerdaf45552013-08-28 00:53:59 +020077 The new file descriptor is now non-inheritable.
Antoine Pitrou09bb89b2012-12-15 21:14:21 +010078
Christian Heimes4fbc72b2008-03-22 00:47:35 +000079
Georg Brandl116aa622007-08-15 14:28:22 +000080.. function:: poll()
81
82 (Not supported by all operating systems.) Returns a polling object, which
83 supports registering and unregistering file descriptors, and then polling them
84 for I/O events; see section :ref:`poll-objects` below for the methods supported
85 by polling objects.
86
87
Christian Heimesfe337bf2008-03-23 21:54:12 +000088.. function:: kqueue()
Christian Heimes4fbc72b2008-03-22 00:47:35 +000089
Georg Brandle767e042010-07-14 08:00:22 +000090 (Only supported on BSD.) Returns a kernel queue object; see section
Christian Heimesfe337bf2008-03-23 21:54:12 +000091 :ref:`kqueue-objects` below for the methods supported by kqueue objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +000092
Victor Stinnerdaf45552013-08-28 00:53:59 +020093 The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
94
95 .. versionchanged:: 3.4
96 The new file descriptor is now non-inheritable.
97
Christian Heimes4fbc72b2008-03-22 00:47:35 +000098
Benjamin Peterson1baf4652009-12-31 03:11:23 +000099.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000100
Georg Brandle767e042010-07-14 08:00:22 +0000101 (Only supported on BSD.) Returns a kernel event object; see section
102 :ref:`kevent-objects` below for the methods supported by kevent objects.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000103
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000104
Georg Brandl734e2682008-08-12 08:18:18 +0000105.. function:: select(rlist, wlist, xlist[, timeout])
Georg Brandl116aa622007-08-15 14:28:22 +0000106
Georg Brandl60203b42010-10-06 10:11:56 +0000107 This is a straightforward interface to the Unix :c:func:`select` system call.
Georg Brandl116aa622007-08-15 14:28:22 +0000108 The first three arguments are sequences of 'waitable objects': either
109 integers representing file descriptors or objects with a parameterless method
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300110 named :meth:`~io.IOBase.fileno` returning such an integer:
Georg Brandl734e2682008-08-12 08:18:18 +0000111
112 * *rlist*: wait until ready for reading
113 * *wlist*: wait until ready for writing
114 * *xlist*: wait for an "exceptional condition" (see the manual page for what
115 your system considers such a condition)
116
117 Empty sequences are allowed, but acceptance of three empty sequences is
118 platform-dependent. (It is known to work on Unix but not on Windows.) The
119 optional *timeout* argument specifies a time-out as a floating point number
120 in seconds. When the *timeout* argument is omitted the function blocks until
121 at least one file descriptor is ready. A time-out value of zero specifies a
122 poll and never blocks.
Georg Brandl116aa622007-08-15 14:28:22 +0000123
124 The return value is a triple of lists of objects that are ready: subsets of the
125 first three arguments. When the time-out is reached without a file descriptor
126 becoming ready, three empty lists are returned.
127
128 .. index::
129 single: socket() (in module socket)
130 single: popen() (in module os)
131
Antoine Pitrou11cb9612010-09-15 11:11:28 +0000132 Among the acceptable object types in the sequences are Python :term:`file
133 objects <file object>` (e.g. ``sys.stdin``, or objects returned by
134 :func:`open` or :func:`os.popen`), socket objects returned by
135 :func:`socket.socket`. You may also define a :dfn:`wrapper` class yourself,
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300136 as long as it has an appropriate :meth:`~io.IOBase.fileno` method (that
137 really returns a file descriptor, not just a random integer).
Georg Brandl116aa622007-08-15 14:28:22 +0000138
Georg Brandl116aa622007-08-15 14:28:22 +0000139 .. note::
140
141 .. index:: single: WinSock
142
Georg Brandl734e2682008-08-12 08:18:18 +0000143 File objects on Windows are not acceptable, but sockets are. On Windows,
Georg Brandl60203b42010-10-06 10:11:56 +0000144 the underlying :c:func:`select` function is provided by the WinSock
Georg Brandl734e2682008-08-12 08:18:18 +0000145 library, and does not handle file descriptors that don't originate from
146 WinSock.
Georg Brandl116aa622007-08-15 14:28:22 +0000147
Antoine Pitroucfad97b2011-01-25 17:24:57 +0000148.. attribute:: PIPE_BUF
Gregory P. Smithb970b862009-07-04 02:28:47 +0000149
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000150 The minimum number of bytes which can be written without blocking to a pipe
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300151 when the pipe has been reported as ready for writing by :func:`~select.select`,
Antoine Pitrouda7be3e2011-01-25 16:28:44 +0000152 :func:`poll` or another interface in this module. This doesn't apply
153 to other kind of file-like objects such as sockets.
154
Amaury Forgeot d'Arcace31022009-07-09 22:44:11 +0000155 This value is guaranteed by POSIX to be at least 512. Availability: Unix.
Gregory P. Smithb970b862009-07-04 02:28:47 +0000156
Mark Dickinson574b1d62009-10-01 20:20:09 +0000157 .. versionadded:: 3.2
Gregory P. Smithb970b862009-07-04 02:28:47 +0000158
Georg Brandl116aa622007-08-15 14:28:22 +0000159
Jesus Cead8b9ae62011-11-14 19:07:41 +0100160.. _devpoll-objects:
161
162``/dev/poll`` Polling Objects
163----------------------------------------------
164
165 http://developers.sun.com/solaris/articles/using_devpoll.html
166 http://developers.sun.com/solaris/articles/polling_efficient.html
167
168Solaris and derivatives have ``/dev/poll``. While :c:func:`select` is
169O(highest file descriptor) and :c:func:`poll` is O(number of file
170descriptors), ``/dev/poll`` is O(active file descriptors).
171
172``/dev/poll`` behaviour is very close to the standard :c:func:`poll`
173object.
174
175
Victor Stinner13423c32013-08-22 00:19:50 +0200176.. method:: devpoll.close()
177
178 Close the file descriptor of the polling object.
179
180 .. versionadded:: 3.4
181
182
183.. attribute:: devpoll.closed
184
185 ``True`` if the polling object is closed.
186
187 .. versionadded:: 3.4
188
189
190.. method:: devpoll.fileno()
191
192 Return the file descriptor number of the polling object.
193
194 .. versionadded:: 3.4
195
196
Jesus Cead8b9ae62011-11-14 19:07:41 +0100197.. method:: devpoll.register(fd[, eventmask])
198
199 Register a file descriptor with the polling object. Future calls to the
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300200 :meth:`poll` method will then check whether the file descriptor has any
201 pending I/O events. *fd* can be either an integer, or an object with a
202 :meth:`~io.IOBase.fileno` method that returns an integer. File objects
203 implement :meth:`!fileno`, so they can also be used as the argument.
Jesus Cead8b9ae62011-11-14 19:07:41 +0100204
205 *eventmask* is an optional bitmask describing the type of events you want to
206 check for. The constants are the same that with :c:func:`poll`
207 object. The default value is a combination of the constants :const:`POLLIN`,
208 :const:`POLLPRI`, and :const:`POLLOUT`.
209
210 .. warning::
211
212 Registering a file descriptor that's already registered is not an
Donald Stufft8b852f12014-05-20 12:58:38 -0400213 error, but the result is undefined. The appropriate action is to
Jesus Cead8b9ae62011-11-14 19:07:41 +0100214 unregister or modify it first. This is an important difference
215 compared with :c:func:`poll`.
216
217
218.. method:: devpoll.modify(fd[, eventmask])
219
220 This method does an :meth:`unregister` followed by a
221 :meth:`register`. It is (a bit) more efficient that doing the same
222 explicitly.
223
224
225.. method:: devpoll.unregister(fd)
226
227 Remove a file descriptor being tracked by a polling object. Just like the
228 :meth:`register` method, *fd* can be an integer or an object with a
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300229 :meth:`~io.IOBase.fileno` method that returns an integer.
Jesus Cead8b9ae62011-11-14 19:07:41 +0100230
231 Attempting to remove a file descriptor that was never registered is
232 safely ignored.
233
234
235.. method:: devpoll.poll([timeout])
236
237 Polls the set of registered file descriptors, and returns a possibly-empty list
238 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
239 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
240 bits set for the reported events for that descriptor --- :const:`POLLIN` for
241 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
242 to, and so forth. An empty list indicates that the call timed out and no file
243 descriptors had any events to report. If *timeout* is given, it specifies the
244 length of time in milliseconds which the system will wait for events before
245 returning. If *timeout* is omitted, -1, or :const:`None`, the call will
246 block until there is an event for this poll object.
247
248
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000249.. _epoll-objects:
250
251Edge and Level Trigger Polling (epoll) Objects
252----------------------------------------------
253
254 http://linux.die.net/man/4/epoll
255
256 *eventmask*
257
258 +-----------------------+-----------------------------------------------+
259 | Constant | Meaning |
260 +=======================+===============================================+
261 | :const:`EPOLLIN` | Available for read |
262 +-----------------------+-----------------------------------------------+
263 | :const:`EPOLLOUT` | Available for write |
264 +-----------------------+-----------------------------------------------+
265 | :const:`EPOLLPRI` | Urgent data for read |
266 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000267 | :const:`EPOLLERR` | Error condition happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000268 +-----------------------+-----------------------------------------------+
Christian Heimes5e696852008-04-09 08:37:03 +0000269 | :const:`EPOLLHUP` | Hang up happened on the assoc. fd |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000270 +-----------------------+-----------------------------------------------+
271 | :const:`EPOLLET` | Set Edge Trigger behavior, the default is |
272 | | Level Trigger behavior |
273 +-----------------------+-----------------------------------------------+
274 | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is |
275 | | pulled out, the fd is internally disabled |
276 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000277 | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000278 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000279 | :const:`EPOLLRDBAND` | Priority data band can be read. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000280 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000281 | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000282 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000283 | :const:`EPOLLWRBAND` | Priority data may be written. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000284 +-----------------------+-----------------------------------------------+
Jean-Paul Calderone7f54dce2010-07-18 16:30:31 +0000285 | :const:`EPOLLMSG` | Ignored. |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000286 +-----------------------+-----------------------------------------------+
287
288
289.. method:: epoll.close()
290
291 Close the control file descriptor of the epoll object.
292
293
Victor Stinner13423c32013-08-22 00:19:50 +0200294.. attribute:: epoll.closed
295
296 ``True`` if the epoll object is closed.
297
298
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000299.. method:: epoll.fileno()
300
301 Return the file descriptor number of the control fd.
302
303
304.. method:: epoll.fromfd(fd)
305
306 Create an epoll object from a given file descriptor.
307
308
309.. method:: epoll.register(fd[, eventmask])
310
311 Register a fd descriptor with the epoll object.
312
313
314.. method:: epoll.modify(fd, eventmask)
315
Georg Brandl632c8122014-01-12 18:03:12 +0100316 Modify a registered file descriptor.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000317
318
319.. method:: epoll.unregister(fd)
320
321 Remove a registered file descriptor from the epoll object.
322
323
Hynek Schlawackdfa46522012-05-21 11:01:54 +0200324.. method:: epoll.poll(timeout=-1, maxevents=-1)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000325
326 Wait for events. timeout in seconds (float)
327
328
Georg Brandl116aa622007-08-15 14:28:22 +0000329.. _poll-objects:
330
331Polling Objects
332---------------
333
Georg Brandl60203b42010-10-06 10:11:56 +0000334The :c:func:`poll` system call, supported on most Unix systems, provides better
Georg Brandl116aa622007-08-15 14:28:22 +0000335scalability for network servers that service many, many clients at the same
Georg Brandl60203b42010-10-06 10:11:56 +0000336time. :c:func:`poll` scales better because the system call only requires listing
337the file descriptors of interest, while :c:func:`select` builds a bitmap, turns
Georg Brandl116aa622007-08-15 14:28:22 +0000338on bits for the fds of interest, and then afterward the whole bitmap has to be
Georg Brandl60203b42010-10-06 10:11:56 +0000339linearly scanned again. :c:func:`select` is O(highest file descriptor), while
340:c:func:`poll` is O(number of file descriptors).
Georg Brandl116aa622007-08-15 14:28:22 +0000341
342
343.. method:: poll.register(fd[, eventmask])
344
345 Register a file descriptor with the polling object. Future calls to the
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300346 :meth:`poll` method will then check whether the file descriptor has any
347 pending I/O events. *fd* can be either an integer, or an object with a
348 :meth:`~io.IOBase.fileno` method that returns an integer. File objects
349 implement :meth:`!fileno`, so they can also be used as the argument.
Georg Brandl116aa622007-08-15 14:28:22 +0000350
351 *eventmask* is an optional bitmask describing the type of events you want to
352 check for, and can be a combination of the constants :const:`POLLIN`,
353 :const:`POLLPRI`, and :const:`POLLOUT`, described in the table below. If not
354 specified, the default value used will check for all 3 types of events.
355
356 +-------------------+------------------------------------------+
357 | Constant | Meaning |
358 +===================+==========================================+
359 | :const:`POLLIN` | There is data to read |
360 +-------------------+------------------------------------------+
361 | :const:`POLLPRI` | There is urgent data to read |
362 +-------------------+------------------------------------------+
363 | :const:`POLLOUT` | Ready for output: writing will not block |
364 +-------------------+------------------------------------------+
365 | :const:`POLLERR` | Error condition of some sort |
366 +-------------------+------------------------------------------+
367 | :const:`POLLHUP` | Hung up |
368 +-------------------+------------------------------------------+
369 | :const:`POLLNVAL` | Invalid request: descriptor not open |
370 +-------------------+------------------------------------------+
371
372 Registering a file descriptor that's already registered is not an error, and has
373 the same effect as registering the descriptor exactly once.
374
375
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000376.. method:: poll.modify(fd, eventmask)
377
378 Modifies an already registered fd. This has the same effect as
Jean-Paul Calderone7f94f392010-07-18 16:13:27 +0000379 ``register(fd, eventmask)``. Attempting to modify a file descriptor
Andrew Svetlov050f9ea2014-04-01 00:23:23 +0300380 that was never registered causes an :exc:`OSError` exception with errno
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000381 :const:`ENOENT` to be raised.
382
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000383
Georg Brandl116aa622007-08-15 14:28:22 +0000384.. method:: poll.unregister(fd)
385
386 Remove a file descriptor being tracked by a polling object. Just like the
387 :meth:`register` method, *fd* can be an integer or an object with a
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300388 :meth:`~io.IOBase.fileno` method that returns an integer.
Georg Brandl116aa622007-08-15 14:28:22 +0000389
390 Attempting to remove a file descriptor that was never registered causes a
391 :exc:`KeyError` exception to be raised.
392
393
394.. method:: poll.poll([timeout])
395
396 Polls the set of registered file descriptors, and returns a possibly-empty list
397 containing ``(fd, event)`` 2-tuples for the descriptors that have events or
398 errors to report. *fd* is the file descriptor, and *event* is a bitmask with
399 bits set for the reported events for that descriptor --- :const:`POLLIN` for
400 waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
401 to, and so forth. An empty list indicates that the call timed out and no file
402 descriptors had any events to report. If *timeout* is given, it specifies the
403 length of time in milliseconds which the system will wait for events before
404 returning. If *timeout* is omitted, negative, or :const:`None`, the call will
405 block until there is an event for this poll object.
406
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000407
408.. _kqueue-objects:
409
410Kqueue Objects
411--------------
412
413.. method:: kqueue.close()
414
415 Close the control file descriptor of the kqueue object.
416
417
Victor Stinner13423c32013-08-22 00:19:50 +0200418.. attribute:: kqueue.closed
419
420 ``True`` if the kqueue object is closed.
421
422
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000423.. method:: kqueue.fileno()
424
425 Return the file descriptor number of the control fd.
426
427
Benjamin Peterson9bc93512008-09-22 22:10:59 +0000428.. method:: kqueue.fromfd(fd)
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000429
430 Create a kqueue object from a given file descriptor.
431
432
Hynek Schlawack979f37a2012-05-22 16:12:18 +0200433.. method:: kqueue.control(changelist, max_events[, timeout=None]) -> eventlist
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000434
435 Low level interface to kevent
436
437 - changelist must be an iterable of kevent object or None
438 - max_events must be 0 or a positive integer
439 - timeout in seconds (floats possible)
440
441
442.. _kevent-objects:
443
444Kevent Objects
445--------------
446
Christian Heimesfe337bf2008-03-23 21:54:12 +0000447http://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000448
Christian Heimesfe337bf2008-03-23 21:54:12 +0000449.. attribute:: kevent.ident
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000450
451 Value used to identify the event. The interpretation depends on the filter
452 but it's usually the file descriptor. In the constructor ident can either
Serhiy Storchaka9e0ae532013-08-24 00:23:38 +0300453 be an int or an object with a :meth:`~io.IOBase.fileno` method. kevent
454 stores the integer internally.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000455
Christian Heimesfe337bf2008-03-23 21:54:12 +0000456.. attribute:: kevent.filter
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000457
Georg Brandl1b5ab452009-08-13 07:56:35 +0000458 Name of the kernel filter.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000459
460 +---------------------------+---------------------------------------------+
461 | Constant | Meaning |
462 +===========================+=============================================+
463 | :const:`KQ_FILTER_READ` | Takes a descriptor and returns whenever |
464 | | there is data available to read |
465 +---------------------------+---------------------------------------------+
466 | :const:`KQ_FILTER_WRITE` | Takes a descriptor and returns whenever |
Georg Brandl1b5ab452009-08-13 07:56:35 +0000467 | | there is data available to write |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000468 +---------------------------+---------------------------------------------+
469 | :const:`KQ_FILTER_AIO` | AIO requests |
470 +---------------------------+---------------------------------------------+
471 | :const:`KQ_FILTER_VNODE` | Returns when one or more of the requested |
472 | | events watched in *fflag* occurs |
473 +---------------------------+---------------------------------------------+
474 | :const:`KQ_FILTER_PROC` | Watch for events on a process id |
475 +---------------------------+---------------------------------------------+
476 | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device |
477 | | [not available on Mac OS X] |
478 +---------------------------+---------------------------------------------+
479 | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is |
480 | | delivered to the process |
481 +---------------------------+---------------------------------------------+
482 | :const:`KQ_FILTER_TIMER` | Establishes an arbitrary timer |
483 +---------------------------+---------------------------------------------+
484
Christian Heimesfe337bf2008-03-23 21:54:12 +0000485.. attribute:: kevent.flags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000486
Georg Brandl1b5ab452009-08-13 07:56:35 +0000487 Filter action.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000488
489 +---------------------------+---------------------------------------------+
490 | Constant | Meaning |
491 +===========================+=============================================+
492 | :const:`KQ_EV_ADD` | Adds or modifies an event |
493 +---------------------------+---------------------------------------------+
494 | :const:`KQ_EV_DELETE` | Removes an event from the queue |
495 +---------------------------+---------------------------------------------+
496 | :const:`KQ_EV_ENABLE` | Permitscontrol() to returns the event |
497 +---------------------------+---------------------------------------------+
498 | :const:`KQ_EV_DISABLE` | Disablesevent |
499 +---------------------------+---------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000500 | :const:`KQ_EV_ONESHOT` | Removes event after first occurrence |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000501 +---------------------------+---------------------------------------------+
502 | :const:`KQ_EV_CLEAR` | Reset the state after an event is retrieved |
503 +---------------------------+---------------------------------------------+
504 | :const:`KQ_EV_SYSFLAGS` | internal event |
505 +---------------------------+---------------------------------------------+
506 | :const:`KQ_EV_FLAG1` | internal event |
507 +---------------------------+---------------------------------------------+
508 | :const:`KQ_EV_EOF` | Filter specific EOF condition |
509 +---------------------------+---------------------------------------------+
510 | :const:`KQ_EV_ERROR` | See return values |
511 +---------------------------+---------------------------------------------+
512
513
Christian Heimesfe337bf2008-03-23 21:54:12 +0000514.. attribute:: kevent.fflags
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000515
Georg Brandl1b5ab452009-08-13 07:56:35 +0000516 Filter specific flags.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000517
Georg Brandl1b5ab452009-08-13 07:56:35 +0000518 :const:`KQ_FILTER_READ` and :const:`KQ_FILTER_WRITE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000519
520 +----------------------------+--------------------------------------------+
521 | Constant | Meaning |
522 +============================+============================================+
523 | :const:`KQ_NOTE_LOWAT` | low water mark of a socket buffer |
524 +----------------------------+--------------------------------------------+
525
Georg Brandl1b5ab452009-08-13 07:56:35 +0000526 :const:`KQ_FILTER_VNODE` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000527
528 +----------------------------+--------------------------------------------+
529 | Constant | Meaning |
530 +============================+============================================+
531 | :const:`KQ_NOTE_DELETE` | *unlink()* was called |
532 +----------------------------+--------------------------------------------+
Georg Brandl2ee470f2008-07-16 12:55:28 +0000533 | :const:`KQ_NOTE_WRITE` | a write occurred |
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000534 +----------------------------+--------------------------------------------+
535 | :const:`KQ_NOTE_EXTEND` | the file was extended |
536 +----------------------------+--------------------------------------------+
537 | :const:`KQ_NOTE_ATTRIB` | an attribute was changed |
538 +----------------------------+--------------------------------------------+
539 | :const:`KQ_NOTE_LINK` | the link count has changed |
540 +----------------------------+--------------------------------------------+
541 | :const:`KQ_NOTE_RENAME` | the file was renamed |
542 +----------------------------+--------------------------------------------+
543 | :const:`KQ_NOTE_REVOKE` | access to the file was revoked |
544 +----------------------------+--------------------------------------------+
545
Georg Brandl1b5ab452009-08-13 07:56:35 +0000546 :const:`KQ_FILTER_PROC` filter flags:
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000547
548 +----------------------------+--------------------------------------------+
549 | Constant | Meaning |
550 +============================+============================================+
551 | :const:`KQ_NOTE_EXIT` | the process has exited |
552 +----------------------------+--------------------------------------------+
553 | :const:`KQ_NOTE_FORK` | the process has called *fork()* |
554 +----------------------------+--------------------------------------------+
555 | :const:`KQ_NOTE_EXEC` | the process has executed a new process |
556 +----------------------------+--------------------------------------------+
557 | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag |
558 +----------------------------+--------------------------------------------+
559 | :const:`KQ_NOTE_PDATAMASK` | internal filter flag |
560 +----------------------------+--------------------------------------------+
561 | :const:`KQ_NOTE_TRACK` | follow a process across *fork()* |
562 +----------------------------+--------------------------------------------+
563 | :const:`KQ_NOTE_CHILD` | returned on the child process for |
564 | | *NOTE_TRACK* |
565 +----------------------------+--------------------------------------------+
566 | :const:`KQ_NOTE_TRACKERR` | unable to attach to a child |
567 +----------------------------+--------------------------------------------+
568
Georg Brandl1b5ab452009-08-13 07:56:35 +0000569 :const:`KQ_FILTER_NETDEV` filter flags (not available on Mac OS X):
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000570
571 +----------------------------+--------------------------------------------+
572 | Constant | Meaning |
573 +============================+============================================+
574 | :const:`KQ_NOTE_LINKUP` | link is up |
575 +----------------------------+--------------------------------------------+
576 | :const:`KQ_NOTE_LINKDOWN` | link is down |
577 +----------------------------+--------------------------------------------+
578 | :const:`KQ_NOTE_LINKINV` | link state is invalid |
579 +----------------------------+--------------------------------------------+
580
581
Christian Heimesfe337bf2008-03-23 21:54:12 +0000582.. attribute:: kevent.data
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000583
Georg Brandl1b5ab452009-08-13 07:56:35 +0000584 Filter specific data.
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000585
586
Christian Heimesfe337bf2008-03-23 21:54:12 +0000587.. attribute:: kevent.udata
Christian Heimes4fbc72b2008-03-22 00:47:35 +0000588
Georg Brandl1b5ab452009-08-13 07:56:35 +0000589 User defined value.