Stream
– stream handle¶
-
class
uv.
Stream
[source]¶ Stream handles provide a reliable ordered duplex communication channel. This is the abstract base class of all stream handles.
-
readable
¶ Stream is readable or not.
Readonly: True Type: bool
-
writeable
¶ Stream is writable or not.
Readonly: True Type: bool
-
read_start
(on_read=None)[source]¶ Start reading data from the stream. The read callback will be called from now on when data has been read.
Raises: - uv.UVError – error while start reading data from the stream
- uv.ClosedHandleError – handle has already been closed or is closing
Parameters: on_read (Callable[[uv.Stream, uv.StatusCodes, bytes], None]) – callback which should be called when data has been read (overrides the current callback if specified)
-
read_stop
()[source]¶ Stop reading data from the stream. The read callback will no longer be called from now on.
Raises: uv.UVError – error while stop reading data from the stream
-
write
(buffers, send_stream=None, on_write=None)[source]¶ Write data to stream. Buffers are written in the given order.
If send_stream is not None and the stream supports inter process communication this method sends send_stream to the other end of the connection.
Parameters: - buffers (tuple[bytes] | list[bytes] | bytes) – data which should be written
- send_stream (uv.TCP | uv.Pipe | None) – stream handle which should be send
- on_write (Callable[[uv.Request, uv.StatusCodes], None]:returns: issued write request) – callback which should run after all data has been written
Return type:
-
shutdown
(on_shutdown=None)[source]¶ Shutdown the outgoing (write) side of a duplex stream. It waits for pending write requests to complete.
Parameters: on_shutdown (Callable[[uv.ShutdownRequest, uv.StatusCodes], None]:returns: issued stream shutdown request) – callback which should run after shutdown has been completed Return type: uv.Request
-
-
class
uv.
UVStream
(loop, ipc, arguments, on_read, on_connection)[source]¶ The base class of all libuv based streams.
Note
This class must not be instantiated directly. Please use the sub-classes for specific communication channels.
Parameters: - loop (uv.Loop) – event loop the handle should run on
- ipc (bool) – stream should support inter process communication or not
- arguments (tuple) – arguments passed to the underling libuv initializer
- on_read (Callable[[uv.UVStream, uv.StatusCodes, bytes], None]:type on_connection: Callable[[uv.UVStream, uv.StatusCodes, bytes], None]) – callback which should be called when data has been read
- on_connection – callback which should run after a new connection has been made or on error (if stream is in listen mode)
-
on_read
¶ Callback which should be called when data has been read.
Note
Data might be a zero-bytes long bytes object. In contrast to the Python standard library this does not indicate any error, especially not EOF.
-
on_read
(stream_handle, status, data) Parameters: - stream_handle (uv.UVStream) – handle the call originates from
- status (uv.StatusCodes) – status of the handle (indicate any errors)
- data (bytes | Any) – data which has been read
Readonly: False Type: Callable[[uv.UVStream, uv.StatusCodes, bytes], None] -
-
on_connection
¶ Callback which should run after a new connection has been made or on error (if stream is in listen mode).
-
on_connection
(stream_handle, status) Parameters: - stream_handle (uv.UVStream) – handle the call originates from
- status (uv.StatusCodes) – status of the new connection
Readonly: False Type: Callable[[uv.UVStream, uv.StatusCodes, uv.UVStream], None] -
-
ipc
¶ Stream does support inter process communication or not.
Readonly: True Type: bool
-
readable
¶ Readonly: True Type: bool
-
writable
¶ Readonly: True Type: bool
-
family
¶ Address family of stream, may be None.
Return type: int | None
-
listen
(backlog=5, on_connection=None)[source]¶ Start listening for incoming connections.
Raises: - uv.UVError – error while start listening for incoming connections
- uv.ClosedHandleError – handle has already been closed or is closing
Parameters: - backlog (int) – number of connections the kernel might queue
- on_connection (Callable[[uv.UVStream, uv.StatusCodes], None]) – callback which should run after a new connection has been made (overrides the current callback if specified)
-
read_start
(on_read=None)[source]¶ Raises: - uv.UVError – error while start reading data from the stream
- uv.ClosedHandleError – handle has already been closed or is closing
-
write
(buffers, send_stream=None, on_write=None)[source]¶ Return type: uv.WriteRequest
-
try_write
(buffers)[source]¶ Immediately write data to the stream without issuing a write request. Throws
uv.error.TemporaryUnavailableError
if data could not be written immediately, otherwise it returns the number of written bytes.Raises: - uv.UVError – error while writing data
- uv.ClosedHandleError – handle has already been closed or is closing
- uv.error.TemporaryUnavailableError – unable to write data immediately
Parameters: buffers (tuple[bytes] | list[bytes] | bytes) – data which should be written
Returns: number of bytes written
Return type:
-
accept
(cls=None, *arguments, **keywords)[source]¶ Accept a new stream. This might be a new client connection or a stream sent by inter process communication.
Warning
There should be no need to use this method directly, it is mainly for internal purposes.
Raises: - uv.UVError – error while accepting incoming stream
- uv.ClosedHandleError – handle has already been closed or is closing
Parameters: Returns: new stream connection of type cls
Return type:
-
class
uv.
ConnectRequest
(stream, arguments, on_connect=None)[source]¶ Request to connect to a specific address.
Note
There is a specific connect request type for every stream type.
Parameters: - stream (uv.UVStream) – stream to establish a connection on
- on_connect (Callable[[uv.ConnectRequest, uv.StatusCodes], None]) – callback which should run after a connection has been established or on error
-
stream
¶ Stream to establish a connection on.
Readonly: True Type: uv.UVStream
-
on_connect
¶ Callback which should run after a connection has been established.
Readonly: False Type: Callable[[uv.ConnectRequest, uv.StatusCodes], None]
-
class
uv.
WriteRequest
(stream, buffers, send_stream=None, on_write=None)[source]¶ Request to write data to a stream and, on streams with inter process communication support, to send stream handles. Buffers are written in the given order.
Raises: - uv.UVError – error while initializing the request
- uv.ClosedHandleError – stream has already been closed or is closing
Parameters: - stream (uv.UVStream) – stream to write data to
- buffers (tuple[bytes] | list[bytes] | bytes) – data which should be written
- send_stream (uv.TCP | uv.Pipe | None) – stream handle which should be send
- on_write (Callable[[uv.WriteRequest, uv.StatusCodes], None]) – callback which should run after all data has been written
-
stream
¶ Stream to write data to.
Readonly: True Type: uv.UVStream
-
send_stream
¶ Stream handle which should be send.
Readonly: True Type: uv.UVStream | None
-
on_write
¶ Callback which should run after all data has been written.
Readonly: False Type: Callable[[uv.WriteRequest, uv.StatusCodes], None]
-
class
uv.
ShutdownRequest
(stream, on_shutdown=None)[source]¶ Request to shutdown the outgoing side of a duplex stream. It waits for pending write requests to complete.
Raises: - uv.UVError – error while initializing the request
- uv.ClosedHandleError – stream has already been closed or is closing
Parameters: - stream (uv.UVStream) – stream to shutdown
- on_shutdown (Callable[[uv.ShutdownRequest, uv.StatusCodes], None]) – callback which should run after shutdown has been completed
-
stream
¶ Stream to shutdown.
Readonly: True Type: uv.UVStream
-
on_shutdown
¶ Callback which should run after shutdown has been completed.
-
on_shutdown
(shutdown_request, status) Parameters: - shutdown_request (uv.ShutdownRequest) – request the call originates from
- status (uv.StatusCodes) – status of the shutdown request
Readonly: False Type: Callable[[uv.ShutdownRequest, uv.StatusCodes], None] -