Poll(fd, loop=None, on_event=None)¶
Poll handles are used to watch file descriptors for readability and writability. The purpose of poll handles is to enable integrating external libraries that rely on the event loop to signal them about the socket status changes. Using them for any other purpose is not recommended. Use
uv.UDP, etc. instead, which provide faster and more scalable implementations, than what can be archived with
uv.Poll, especially on Windows.
It is possible that poll handles occasionally signal that a file descriptor is readable or writable even when it is not. The user should therefore always be prepared to handle EAGAIN or equivalent when it attempts to read from or write to the fd.
It is not okay to have multiple active poll handles for the same socket, this can cause libuv to busyloop or otherwise malfunction.
Do not close a file descriptor while it is being polled by an active poll handle. This can cause the handle to report an error, but it might also start polling another socket. However the fd can be safely closed immediately after
uv.Handle.close()has been called.
On Windows only sockets can be polled with
uv.Pollhandles. On Unix any file descriptor that would be accepted by poll(2) can be used.
uv.UVError – error while initializing the handle
File descriptor the handle polls on.
Readonly: True Type: int
Callback which should be called on IO events after the handle has been started.
on_event(poll_handle, status, events)
Parameters: Readonly: False Type: Callable[[uv.Poll, uv.StatusCode, int], None]
start(events=<PollEvent.READABLE: 1>, on_event=None)¶
Start polling the file descriptor for the given events. As soon as an event is detected the callback will be called with status code class:uv.StatusCode.SUCCESS and the triggered events.
If an error happens while polling the callback gets called with status code != 0 which corresponds to a
Calling this on a handle that is already active is fine. Doing so will update the events mask that is being polled for.
- uv.UVError – error while starting the handle
- uv.ClosedHandleError – handle has already been closed or is closing
- events (int) – bitmask of events to be polled for
- on_event (Callable[[uv.Poll, uv.StatusCode, int], None]) – callback which should be called on IO events (overrides the current callback if specified)
Stop the handle. The callback will no longer be called.
- :raises uv.UVError
- error while stopping the handle