BaseSelector class in selectors:
A BaseSelector is used to wait for I/O event readiness on multiple file objects. It supports file stream registration, unregistration, and a method to wait for I/O events on those streams, with an optional timeout. It's an abstract base class, so cannot be instantiated. Use DefaultSelector instead, or one of SelectSelector, KqueueSelector etc. if you want to specifically use an implementation, and your platform supports it. BaseSelector and its concrete implementations support the context manager protocol.
abstractmethod register(fileobj, events, data=None)
Register a file object for selection, monitoring it for I/O events.
fileobj is the file object to monitor. It may either be an integer file descriptor or an object with a fileno() method. events is a bitwise mask of events to monitor. data is an opaque object.
This returns a new SelectorKey instance, or raises a ValueError in case of invalid event mask or file descriptor, or KeyError if the file object is already registered.
Unregister a file object from selection, removing it from monitoring. A file object shall be unregistered prior to being closed.
fileobj must be a file object previously registered.
This returns the associated SelectorKey instance, or raises a KeyError if fileobj is not registered. It will raise ValueError if fileobj is invalid (e.g. it has no fileno() method or its fileno() method has an invalid return value).
modify(fileobj, events, data=None)
Change a registered file objects monitored events or attached data.
This is equivalent to BaseSelector.unregister(fileobj)() followed by BaseSelector.register(fileobj, events, data)(), except that it can be implemented more efficiently.
This returns a new SelectorKey instance, or raises a ValueError in case of invalid event mask or file descriptor, or KeyError if the file object is not registered.
Wait until some registered file objects become ready, or the timeout expires.
If timeout > 0, this specifies the maximum wait time, in seconds. If timeout <= 0, the call won't block, and will report the currently ready file objects. If timeout is None, the call will block until a monitored file object becomes ready.
This returns a list of (key, events) tuples, one for each ready file object.
key is the SelectorKey instance corresponding to a ready file object. events is a bitmask of events ready on this file object.