• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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--------------
8
9This module provides access to the :c:func:`select` and :c:func:`poll` functions
10available in most operating systems, :c:func:`devpoll` available on
11Solaris and derivatives, :c:func:`epoll` available on Linux 2.5+ and
12:c:func:`kqueue` available on most BSD.
13Note that on Windows, it only works for sockets; on other operating systems,
14it also works for other file types (in particular, on Unix, it works on pipes).
15It cannot be used on regular files to determine whether a file has grown since
16it was last read.
17
18.. note::
19
20   The :mod:`selectors` module allows high-level and efficient I/O
21   multiplexing, built upon the :mod:`select` module primitives. Users are
22   encouraged to use the :mod:`selectors` module instead, unless they want
23   precise control over the OS-level primitives used.
24
25
26The module defines the following:
27
28
29.. exception:: error
30
31   A deprecated alias of :exc:`OSError`.
32
33   .. versionchanged:: 3.3
34      Following :pep:`3151`, this class was made an alias of :exc:`OSError`.
35
36
37.. function:: devpoll()
38
39   (Only supported on Solaris and derivatives.)  Returns a ``/dev/poll``
40   polling object; see section :ref:`devpoll-objects` below for the
41   methods supported by devpoll objects.
42
43   :c:func:`devpoll` objects are linked to the number of file
44   descriptors allowed at the time of instantiation. If your program
45   reduces this value, :c:func:`devpoll` will fail. If your program
46   increases this value, :c:func:`devpoll` may return an
47   incomplete list of active file descriptors.
48
49   The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
50
51   .. versionadded:: 3.3
52
53   .. versionchanged:: 3.4
54      The new file descriptor is now non-inheritable.
55
56.. function:: epoll(sizehint=-1, flags=0)
57
58   (Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
59   which can be used as Edge or Level Triggered interface for I/O
60   events.
61
62   *sizehint* informs epoll about the expected number of events to be
63   registered.  It must be positive, or `-1` to use the default. It is only
64   used on older systems where :c:func:`epoll_create1` is not available;
65   otherwise it has no effect (though its value is still checked).
66
67   *flags* is deprecated and completely ignored.  However, when supplied, its
68   value must be ``0`` or ``select.EPOLL_CLOEXEC``, otherwise ``OSError`` is
69   raised.
70
71   See the :ref:`epoll-objects` section below for the methods supported by
72   epolling objects.
73
74   ``epoll`` objects support the context management protocol: when used in a
75   :keyword:`with` statement, the new file descriptor is automatically closed
76   at the end of the block.
77
78   The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
79
80   .. versionchanged:: 3.3
81      Added the *flags* parameter.
82
83   .. versionchanged:: 3.4
84      Support for the :keyword:`with` statement was added.
85      The new file descriptor is now non-inheritable.
86
87   .. deprecated:: 3.4
88      The *flags* parameter.  ``select.EPOLL_CLOEXEC`` is used by default now.
89      Use :func:`os.set_inheritable` to make the file descriptor inheritable.
90
91
92.. function:: poll()
93
94   (Not supported by all operating systems.)  Returns a polling object, which
95   supports registering and unregistering file descriptors, and then polling them
96   for I/O events; see section :ref:`poll-objects` below for the methods supported
97   by polling objects.
98
99
100.. function:: kqueue()
101
102   (Only supported on BSD.)  Returns a kernel queue object; see section
103   :ref:`kqueue-objects` below for the methods supported by kqueue objects.
104
105   The new file descriptor is :ref:`non-inheritable <fd_inheritance>`.
106
107   .. versionchanged:: 3.4
108      The new file descriptor is now non-inheritable.
109
110
111.. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
112
113   (Only supported on BSD.)  Returns a kernel event object; see section
114   :ref:`kevent-objects` below for the methods supported by kevent objects.
115
116
117.. function:: select(rlist, wlist, xlist[, timeout])
118
119   This is a straightforward interface to the Unix :c:func:`select` system call.
120   The first three arguments are iterables of 'waitable objects': either
121   integers representing file descriptors or objects with a parameterless method
122   named :meth:`~io.IOBase.fileno` returning such an integer:
123
124   * *rlist*: wait until ready for reading
125   * *wlist*: wait until ready for writing
126   * *xlist*: wait for an "exceptional condition" (see the manual page for what
127     your system considers such a condition)
128
129   Empty iterables are allowed, but acceptance of three empty iterables is
130   platform-dependent. (It is known to work on Unix but not on Windows.)  The
131   optional *timeout* argument specifies a time-out as a floating point number
132   in seconds.  When the *timeout* argument is omitted the function blocks until
133   at least one file descriptor is ready.  A time-out value of zero specifies a
134   poll and never blocks.
135
136   The return value is a triple of lists of objects that are ready: subsets of the
137   first three arguments.  When the time-out is reached without a file descriptor
138   becoming ready, three empty lists are returned.
139
140   .. index::
141      single: socket() (in module socket)
142      single: popen() (in module os)
143
144   Among the acceptable object types in the iterables are Python :term:`file
145   objects <file object>` (e.g. ``sys.stdin``, or objects returned by
146   :func:`open` or :func:`os.popen`), socket objects returned by
147   :func:`socket.socket`.  You may also define a :dfn:`wrapper` class yourself,
148   as long as it has an appropriate :meth:`~io.IOBase.fileno` method (that
149   really returns a file descriptor, not just a random integer).
150
151   .. note::
152
153      .. index:: single: WinSock
154
155      File objects on Windows are not acceptable, but sockets are.  On Windows,
156      the underlying :c:func:`select` function is provided by the WinSock
157      library, and does not handle file descriptors that don't originate from
158      WinSock.
159
160   .. versionchanged:: 3.5
161      The function is now retried with a recomputed timeout when interrupted by
162      a signal, except if the signal handler raises an exception (see
163      :pep:`475` for the rationale), instead of raising
164      :exc:`InterruptedError`.
165
166
167.. attribute:: PIPE_BUF
168
169   The minimum number of bytes which can be written without blocking to a pipe
170   when the pipe has been reported as ready for writing by :func:`~select.select`,
171   :func:`poll` or another interface in this module.  This doesn't apply
172   to other kind of file-like objects such as sockets.
173
174   This value is guaranteed by POSIX to be at least 512.
175
176   .. availability:: Unix
177
178   .. versionadded:: 3.2
179
180
181.. _devpoll-objects:
182
183``/dev/poll`` Polling Objects
184-----------------------------
185
186Solaris and derivatives have ``/dev/poll``. While :c:func:`select` is
187O(highest file descriptor) and :c:func:`poll` is O(number of file
188descriptors), ``/dev/poll`` is O(active file descriptors).
189
190``/dev/poll`` behaviour is very close to the standard :c:func:`poll`
191object.
192
193
194.. method:: devpoll.close()
195
196   Close the file descriptor of the polling object.
197
198   .. versionadded:: 3.4
199
200
201.. attribute:: devpoll.closed
202
203   ``True`` if the polling object is closed.
204
205   .. versionadded:: 3.4
206
207
208.. method:: devpoll.fileno()
209
210   Return the file descriptor number of the polling object.
211
212   .. versionadded:: 3.4
213
214
215.. method:: devpoll.register(fd[, eventmask])
216
217   Register a file descriptor with the polling object.  Future calls to the
218   :meth:`poll` method will then check whether the file descriptor has any
219   pending I/O events.  *fd* can be either an integer, or an object with a
220   :meth:`~io.IOBase.fileno` method that returns an integer.  File objects
221   implement :meth:`!fileno`, so they can also be used as the argument.
222
223   *eventmask* is an optional bitmask describing the type of events you want to
224   check for. The constants are the same that with :c:func:`poll`
225   object. The default value is a combination of the constants :const:`POLLIN`,
226   :const:`POLLPRI`, and :const:`POLLOUT`.
227
228   .. warning::
229
230      Registering a file descriptor that's already registered is not an
231      error, but the result is undefined. The appropriate action is to
232      unregister or modify it first. This is an important difference
233      compared with :c:func:`poll`.
234
235
236.. method:: devpoll.modify(fd[, eventmask])
237
238   This method does an :meth:`unregister` followed by a
239   :meth:`register`. It is (a bit) more efficient that doing the same
240   explicitly.
241
242
243.. method:: devpoll.unregister(fd)
244
245   Remove a file descriptor being tracked by a polling object.  Just like the
246   :meth:`register` method, *fd* can be an integer or an object with a
247   :meth:`~io.IOBase.fileno` method that returns an integer.
248
249   Attempting to remove a file descriptor that was never registered is
250   safely ignored.
251
252
253.. method:: devpoll.poll([timeout])
254
255   Polls the set of registered file descriptors, and returns a possibly-empty list
256   containing ``(fd, event)`` 2-tuples for the descriptors that have events or
257   errors to report. *fd* is the file descriptor, and *event* is a bitmask with
258   bits set for the reported events for that descriptor --- :const:`POLLIN` for
259   waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
260   to, and so forth. An empty list indicates that the call timed out and no file
261   descriptors had any events to report. If *timeout* is given, it specifies the
262   length of time in milliseconds which the system will wait for events before
263   returning. If *timeout* is omitted, -1, or :const:`None`, the call will
264   block until there is an event for this poll object.
265
266   .. versionchanged:: 3.5
267      The function is now retried with a recomputed timeout when interrupted by
268      a signal, except if the signal handler raises an exception (see
269      :pep:`475` for the rationale), instead of raising
270      :exc:`InterruptedError`.
271
272
273.. _epoll-objects:
274
275Edge and Level Trigger Polling (epoll) Objects
276----------------------------------------------
277
278   https://linux.die.net/man/4/epoll
279
280   *eventmask*
281
282   +-------------------------+-----------------------------------------------+
283   | Constant                | Meaning                                       |
284   +=========================+===============================================+
285   | :const:`EPOLLIN`        | Available for read                            |
286   +-------------------------+-----------------------------------------------+
287   | :const:`EPOLLOUT`       | Available for write                           |
288   +-------------------------+-----------------------------------------------+
289   | :const:`EPOLLPRI`       | Urgent data for read                          |
290   +-------------------------+-----------------------------------------------+
291   | :const:`EPOLLERR`       | Error condition happened on the assoc. fd     |
292   +-------------------------+-----------------------------------------------+
293   | :const:`EPOLLHUP`       | Hang up happened on the assoc. fd             |
294   +-------------------------+-----------------------------------------------+
295   | :const:`EPOLLET`        | Set Edge Trigger behavior, the default is     |
296   |                         | Level Trigger behavior                        |
297   +-------------------------+-----------------------------------------------+
298   | :const:`EPOLLONESHOT`   | Set one-shot behavior. After one event is     |
299   |                         | pulled out, the fd is internally disabled     |
300   +-------------------------+-----------------------------------------------+
301   | :const:`EPOLLEXCLUSIVE` | Wake only one epoll object when the           |
302   |                         | associated fd has an event. The default (if   |
303   |                         | this flag is not set) is to wake all epoll    |
304   |                         | objects polling on a fd.                      |
305   +-------------------------+-----------------------------------------------+
306   | :const:`EPOLLRDHUP`     | Stream socket peer closed connection or shut  |
307   |                         | down writing half of connection.              |
308   +-------------------------+-----------------------------------------------+
309   | :const:`EPOLLRDNORM`    | Equivalent to :const:`EPOLLIN`                |
310   +-------------------------+-----------------------------------------------+
311   | :const:`EPOLLRDBAND`    | Priority data band can be read.               |
312   +-------------------------+-----------------------------------------------+
313   | :const:`EPOLLWRNORM`    | Equivalent to :const:`EPOLLOUT`               |
314   +-------------------------+-----------------------------------------------+
315   | :const:`EPOLLWRBAND`    | Priority data may be written.                 |
316   +-------------------------+-----------------------------------------------+
317   | :const:`EPOLLMSG`       | Ignored.                                      |
318   +-------------------------+-----------------------------------------------+
319
320   .. versionadded:: 3.6
321      :const:`EPOLLEXCLUSIVE` was added.  It's only supported by Linux Kernel 4.5
322      or later.
323
324.. method:: epoll.close()
325
326   Close the control file descriptor of the epoll object.
327
328
329.. attribute:: epoll.closed
330
331   ``True`` if the epoll object is closed.
332
333
334.. method:: epoll.fileno()
335
336   Return the file descriptor number of the control fd.
337
338
339.. method:: epoll.fromfd(fd)
340
341   Create an epoll object from a given file descriptor.
342
343
344.. method:: epoll.register(fd[, eventmask])
345
346   Register a fd descriptor with the epoll object.
347
348
349.. method:: epoll.modify(fd, eventmask)
350
351   Modify a registered file descriptor.
352
353
354.. method:: epoll.unregister(fd)
355
356   Remove a registered file descriptor from the epoll object.
357
358   .. versionchanged:: 3.9
359      The method no longer ignores the :data:`~errno.EBADF` error.
360
361
362.. method:: epoll.poll(timeout=None, maxevents=-1)
363
364   Wait for events. timeout in seconds (float)
365
366   .. versionchanged:: 3.5
367      The function is now retried with a recomputed timeout when interrupted by
368      a signal, except if the signal handler raises an exception (see
369      :pep:`475` for the rationale), instead of raising
370      :exc:`InterruptedError`.
371
372
373.. _poll-objects:
374
375Polling Objects
376---------------
377
378The :c:func:`poll` system call, supported on most Unix systems, provides better
379scalability for network servers that service many, many clients at the same
380time. :c:func:`poll` scales better because the system call only requires listing
381the file descriptors of interest, while :c:func:`select` builds a bitmap, turns
382on bits for the fds of interest, and then afterward the whole bitmap has to be
383linearly scanned again. :c:func:`select` is O(highest file descriptor), while
384:c:func:`poll` is O(number of file descriptors).
385
386
387.. method:: poll.register(fd[, eventmask])
388
389   Register a file descriptor with the polling object.  Future calls to the
390   :meth:`poll` method will then check whether the file descriptor has any
391   pending I/O events.  *fd* can be either an integer, or an object with a
392   :meth:`~io.IOBase.fileno` method that returns an integer.  File objects
393   implement :meth:`!fileno`, so they can also be used as the argument.
394
395   *eventmask* is an optional bitmask describing the type of events you want to
396   check for, and can be a combination of the constants :const:`POLLIN`,
397   :const:`POLLPRI`, and :const:`POLLOUT`, described in the table below.  If not
398   specified, the default value used will check for all 3 types of events.
399
400   +-------------------+------------------------------------------+
401   | Constant          | Meaning                                  |
402   +===================+==========================================+
403   | :const:`POLLIN`   | There is data to read                    |
404   +-------------------+------------------------------------------+
405   | :const:`POLLPRI`  | There is urgent data to read             |
406   +-------------------+------------------------------------------+
407   | :const:`POLLOUT`  | Ready for output: writing will not block |
408   +-------------------+------------------------------------------+
409   | :const:`POLLERR`  | Error condition of some sort             |
410   +-------------------+------------------------------------------+
411   | :const:`POLLHUP`  | Hung up                                  |
412   +-------------------+------------------------------------------+
413   | :const:`POLLRDHUP`| Stream socket peer closed connection, or |
414   |                   | shut down writing half of connection     |
415   +-------------------+------------------------------------------+
416   | :const:`POLLNVAL` | Invalid request: descriptor not open     |
417   +-------------------+------------------------------------------+
418
419   Registering a file descriptor that's already registered is not an error, and has
420   the same effect as registering the descriptor exactly once.
421
422
423.. method:: poll.modify(fd, eventmask)
424
425   Modifies an already registered fd. This has the same effect as
426   ``register(fd, eventmask)``.  Attempting to modify a file descriptor
427   that was never registered causes an :exc:`OSError` exception with errno
428   :const:`ENOENT` to be raised.
429
430
431.. method:: poll.unregister(fd)
432
433   Remove a file descriptor being tracked by a polling object.  Just like the
434   :meth:`register` method, *fd* can be an integer or an object with a
435   :meth:`~io.IOBase.fileno` method that returns an integer.
436
437   Attempting to remove a file descriptor that was never registered causes a
438   :exc:`KeyError` exception to be raised.
439
440
441.. method:: poll.poll([timeout])
442
443   Polls the set of registered file descriptors, and returns a possibly-empty list
444   containing ``(fd, event)`` 2-tuples for the descriptors that have events or
445   errors to report. *fd* is the file descriptor, and *event* is a bitmask with
446   bits set for the reported events for that descriptor --- :const:`POLLIN` for
447   waiting input, :const:`POLLOUT` to indicate that the descriptor can be written
448   to, and so forth. An empty list indicates that the call timed out and no file
449   descriptors had any events to report. If *timeout* is given, it specifies the
450   length of time in milliseconds which the system will wait for events before
451   returning. If *timeout* is omitted, negative, or :const:`None`, the call will
452   block until there is an event for this poll object.
453
454   .. versionchanged:: 3.5
455      The function is now retried with a recomputed timeout when interrupted by
456      a signal, except if the signal handler raises an exception (see
457      :pep:`475` for the rationale), instead of raising
458      :exc:`InterruptedError`.
459
460
461.. _kqueue-objects:
462
463Kqueue Objects
464--------------
465
466.. method:: kqueue.close()
467
468   Close the control file descriptor of the kqueue object.
469
470
471.. attribute:: kqueue.closed
472
473   ``True`` if the kqueue object is closed.
474
475
476.. method:: kqueue.fileno()
477
478   Return the file descriptor number of the control fd.
479
480
481.. method:: kqueue.fromfd(fd)
482
483   Create a kqueue object from a given file descriptor.
484
485
486.. method:: kqueue.control(changelist, max_events[, timeout]) -> eventlist
487
488   Low level interface to kevent
489
490   - changelist must be an iterable of kevent objects or ``None``
491   - max_events must be 0 or a positive integer
492   - timeout in seconds (floats possible); the default is ``None``,
493     to wait forever
494
495   .. versionchanged:: 3.5
496      The function is now retried with a recomputed timeout when interrupted by
497      a signal, except if the signal handler raises an exception (see
498      :pep:`475` for the rationale), instead of raising
499      :exc:`InterruptedError`.
500
501
502.. _kevent-objects:
503
504Kevent Objects
505--------------
506
507https://www.freebsd.org/cgi/man.cgi?query=kqueue&sektion=2
508
509.. attribute:: kevent.ident
510
511   Value used to identify the event. The interpretation depends on the filter
512   but it's usually the file descriptor. In the constructor ident can either
513   be an int or an object with a :meth:`~io.IOBase.fileno` method. kevent
514   stores the integer internally.
515
516.. attribute:: kevent.filter
517
518   Name of the kernel filter.
519
520   +---------------------------+---------------------------------------------+
521   | Constant                  | Meaning                                     |
522   +===========================+=============================================+
523   | :const:`KQ_FILTER_READ`   | Takes a descriptor and returns whenever     |
524   |                           | there is data available to read             |
525   +---------------------------+---------------------------------------------+
526   | :const:`KQ_FILTER_WRITE`  | Takes a descriptor and returns whenever     |
527   |                           | there is data available to write            |
528   +---------------------------+---------------------------------------------+
529   | :const:`KQ_FILTER_AIO`    | AIO requests                                |
530   +---------------------------+---------------------------------------------+
531   | :const:`KQ_FILTER_VNODE`  | Returns when one or more of the requested   |
532   |                           | events watched in *fflag* occurs            |
533   +---------------------------+---------------------------------------------+
534   | :const:`KQ_FILTER_PROC`   | Watch for events on a process id            |
535   +---------------------------+---------------------------------------------+
536   | :const:`KQ_FILTER_NETDEV` | Watch for events on a network device        |
537   |                           | [not available on macOS]                    |
538   +---------------------------+---------------------------------------------+
539   | :const:`KQ_FILTER_SIGNAL` | Returns whenever the watched signal is      |
540   |                           | delivered to the process                    |
541   +---------------------------+---------------------------------------------+
542   | :const:`KQ_FILTER_TIMER`  | Establishes an arbitrary timer              |
543   +---------------------------+---------------------------------------------+
544
545.. attribute:: kevent.flags
546
547   Filter action.
548
549   +---------------------------+---------------------------------------------+
550   | Constant                  | Meaning                                     |
551   +===========================+=============================================+
552   | :const:`KQ_EV_ADD`        | Adds or modifies an event                   |
553   +---------------------------+---------------------------------------------+
554   | :const:`KQ_EV_DELETE`     | Removes an event from the queue             |
555   +---------------------------+---------------------------------------------+
556   | :const:`KQ_EV_ENABLE`     | Permitscontrol() to returns the event       |
557   +---------------------------+---------------------------------------------+
558   | :const:`KQ_EV_DISABLE`    | Disablesevent                               |
559   +---------------------------+---------------------------------------------+
560   | :const:`KQ_EV_ONESHOT`    | Removes event after first occurrence        |
561   +---------------------------+---------------------------------------------+
562   | :const:`KQ_EV_CLEAR`      | Reset the state after an event is retrieved |
563   +---------------------------+---------------------------------------------+
564   | :const:`KQ_EV_SYSFLAGS`   | internal event                              |
565   +---------------------------+---------------------------------------------+
566   | :const:`KQ_EV_FLAG1`      | internal event                              |
567   +---------------------------+---------------------------------------------+
568   | :const:`KQ_EV_EOF`        | Filter specific EOF condition               |
569   +---------------------------+---------------------------------------------+
570   | :const:`KQ_EV_ERROR`      | See return values                           |
571   +---------------------------+---------------------------------------------+
572
573
574.. attribute:: kevent.fflags
575
576   Filter specific flags.
577
578   :const:`KQ_FILTER_READ` and  :const:`KQ_FILTER_WRITE` filter flags:
579
580   +----------------------------+--------------------------------------------+
581   | Constant                   | Meaning                                    |
582   +============================+============================================+
583   | :const:`KQ_NOTE_LOWAT`     | low water mark of a socket buffer          |
584   +----------------------------+--------------------------------------------+
585
586   :const:`KQ_FILTER_VNODE` filter flags:
587
588   +----------------------------+--------------------------------------------+
589   | Constant                   | Meaning                                    |
590   +============================+============================================+
591   | :const:`KQ_NOTE_DELETE`    | *unlink()* was called                      |
592   +----------------------------+--------------------------------------------+
593   | :const:`KQ_NOTE_WRITE`     | a write occurred                           |
594   +----------------------------+--------------------------------------------+
595   | :const:`KQ_NOTE_EXTEND`    | the file was extended                      |
596   +----------------------------+--------------------------------------------+
597   | :const:`KQ_NOTE_ATTRIB`    | an attribute was changed                   |
598   +----------------------------+--------------------------------------------+
599   | :const:`KQ_NOTE_LINK`      | the link count has changed                 |
600   +----------------------------+--------------------------------------------+
601   | :const:`KQ_NOTE_RENAME`    | the file was renamed                       |
602   +----------------------------+--------------------------------------------+
603   | :const:`KQ_NOTE_REVOKE`    | access to the file was revoked             |
604   +----------------------------+--------------------------------------------+
605
606   :const:`KQ_FILTER_PROC` filter flags:
607
608   +----------------------------+--------------------------------------------+
609   | Constant                   | Meaning                                    |
610   +============================+============================================+
611   | :const:`KQ_NOTE_EXIT`      | the process has exited                     |
612   +----------------------------+--------------------------------------------+
613   | :const:`KQ_NOTE_FORK`      | the process has called *fork()*            |
614   +----------------------------+--------------------------------------------+
615   | :const:`KQ_NOTE_EXEC`      | the process has executed a new process     |
616   +----------------------------+--------------------------------------------+
617   | :const:`KQ_NOTE_PCTRLMASK` | internal filter flag                       |
618   +----------------------------+--------------------------------------------+
619   | :const:`KQ_NOTE_PDATAMASK` | internal filter flag                       |
620   +----------------------------+--------------------------------------------+
621   | :const:`KQ_NOTE_TRACK`     | follow a process across *fork()*           |
622   +----------------------------+--------------------------------------------+
623   | :const:`KQ_NOTE_CHILD`     | returned on the child process for          |
624   |                            | *NOTE_TRACK*                               |
625   +----------------------------+--------------------------------------------+
626   | :const:`KQ_NOTE_TRACKERR`  | unable to attach to a child                |
627   +----------------------------+--------------------------------------------+
628
629   :const:`KQ_FILTER_NETDEV` filter flags (not available on macOS):
630
631   +----------------------------+--------------------------------------------+
632   | Constant                   | Meaning                                    |
633   +============================+============================================+
634   | :const:`KQ_NOTE_LINKUP`    | link is up                                 |
635   +----------------------------+--------------------------------------------+
636   | :const:`KQ_NOTE_LINKDOWN`  | link is down                               |
637   +----------------------------+--------------------------------------------+
638   | :const:`KQ_NOTE_LINKINV`   | link state is invalid                      |
639   +----------------------------+--------------------------------------------+
640
641
642.. attribute:: kevent.data
643
644   Filter specific data.
645
646
647.. attribute:: kevent.udata
648
649   User defined value.
650