# gevent

# `gevent.selectors` – High-level IO Multiplexing

This module provides `GeventSelector`, a high-level IO multiplexing mechanism. This is aliased to `DefaultSelector`.

This module provides the same API as the selectors defined in `selectors`.

On Python 2, this module is only available if the selectors2 backport is installed.

New in version 20.6.0.

DefaultSelector

  alias of `gevent.selectors.GeventSelector`

class GeventSelector(hub=None)

  Bases: `selectors._BaseSelectorImpl`

  A selector implementation using gevent primitives.

  This is a type of `selectors.BaseSelector`, so the documentation for that class applies here.

  Caution

  As the base class indicates, it is critically important to unregister file objects before closing them. (Or close the selector they are registered with before closing them.) Failure to do so may crash the process or have other unintended results.

  close()

    Close the selector.

    This must be called to make sure that any underlying resource is freed.

  register(fileobj, events, data=None)

    Register a file object.

    Parameters: fileobj – file object or file descriptor events – events to monitor (bitwise mask of EVENT_READ|EVENT_WRITE) data – attached data

    Returns: SelectorKey instance

    Raises: ValueError if events is invalid KeyError if fileobj is already registered OSError if fileobj is closed or otherwise is unacceptable to

    > the underlying system call (if a system call is made)

    Note: OSError may or may not be raised

  select(timeout=None)

    Poll for I/O.

    Note that, like the built-in selectors, this will block indefinitely if no timeout is given and no files have been registered.

  unregister(fileobj)

    Unregister a file object.

    Parameters: fileobj – file object or file descriptor

    Returns: SelectorKey instance

    Raises: KeyError if fileobj is not registered

    Note: If fileobj is registered but has since been closed this does not raise OSError (even if the wrapped syscall does)

Next page: `gevent.event` – Notifications of multiple listeners