Python API reference#
pw_rpc2: Next gen, zero-copy async RPC with end-to-end backpressure
Generated API reference for the pw_rpc2 Python package
(//pw_rpc2/py:pw_rpc2). For usage guides and examples, see
Python client.
pw_rpc2#
Python client for pw_rpc2.
Client is a synchronous, thread-safe client;
pw_rpc2.aio.Client is its asyncio counterpart.
Client and services#
- class pw_rpc2.Client(
- socket: ReliableSocket,
- protos: Iterable[ModuleType | FileDescriptor | ServiceDescriptor] = (),
- *,
- default_timeout: float | None = None,
- handshake_timeout: float = 5.0,
A synchronous client for a pw_rpc2 server.
The client owns its
ReliableSocket; closing the client closes the socket and ends any active calls withCLOSED. A background thread receives packets from the server.- __init__(
- socket: ReliableSocket,
- protos: Iterable[ModuleType | FileDescriptor | ServiceDescriptor] = (),
- *,
- default_timeout: float | None = None,
- handshake_timeout: float = 5.0,
Performs the server handshake over
socket.- Parameters:
socket – A connected
ReliableSocket, which the client takes ownership of.protos – Generated protobuf modules or descriptors of the services to create service clients for.
default_timeout – The default for how long operations wait for a response from the server, in seconds;
Nonewaits forever.handshake_timeout – How long to wait for the server to reply to the connection handshake, in seconds.
- Raises:
HandshakeError – The server did not complete the handshake.
TypeError – Something in
protosdoes not describe services.ValueError – Services or methods with different names have the same ID, a service and a package share a name, or a timeout is negative.
- add_services(
- protos: Iterable[ModuleType | FileDescriptor | ServiceDescriptor],
Creates service clients for more services.
A service with the same name as an existing service replaces it.
- Raises:
TypeError – Something in
protosdoes not describe services.ValueError – Services or methods with different names have the same ID, or a service and a package share a name.
- property default_timeout: float | None#
How long operations wait for a response by default, in seconds.
Nonewaits forever.
- methods() Iterator[MethodClient]#
Yields every method client across all registered services.
- property rpcs: Services[MethodClient]#
The service clients, e.g.
client.rpcs.examples.Echo.
- class pw_rpc2.Services(services: Iterable[ServiceClient[MethodClientT]] = ())#
RPC services, navigable by protobuf package.
Attribute access walks the package hierarchy (
rpcs.examples.Echo). Services can also be looked up by their full name (rpcs['examples.Echo']), and iterating yields every service.- __init__(services: Iterable[ServiceClient[MethodClientT]] = ()) None#
- class pw_rpc2.Package(name: str)#
A protobuf package, whose services and subpackages are attributes.
- class pw_rpc2.ServiceClient(
- service: Service,
- make_method: Callable[[Method], MethodClientT],
The method clients of a service, accessible as attributes or by name.
- property descriptor: ServiceDescriptor#
The protobuf
ServiceDescriptorfor this service.
- class pw_rpc2.MethodClient(client: Client, method: Method)#
Invokes an RPC method.
For unary methods, calling the method client waits for and returns the response. For streaming methods, it starts the RPC and returns its call object.
Requests are given either as a message or as keyword arguments for the request’s fields:
echo.Echo(EchoMessage(msg='hello')) echo.Echo(msg='hello')
The
rpc2_timeoutkeyword argument sets the call’s timeout. It has a prefix so that it does not collide with a request field namedtimeout; a field namedrpc2_timeoutcan only be set by passing a message.- property descriptor: MethodDescriptor#
The protobuf
MethodDescriptorfor this method.
- invoke( ) Call#
Starts the RPC without waiting for a response.
- Parameters:
request – The request message; streaming requests are instead sent with the call’s
write()method.rpc2_timeout – Default timeout for waiting on a response from the server, in seconds.
Noneuses the client’s default.**fields – Request fields, as an alternative to
request.
- Returns:
A call object whose type depends on the RPC type.
- Raises:
TypeError – The request is invalid.
ValueError – A field name is not in the request type, the request is too large for the socket, or the timeout is negative.
DecodeError – A malformed packet closed the connection.
SocketClosed – The connection is closed.
- property type: MethodType#
The method’s
MethodTypestreaming mode.
- class pw_rpc2.MethodType(*values)#
The streaming mode of an RPC method.
- BIDIRECTIONAL_STREAMING = (True, True)#
- CLIENT_STREAMING = (True, False)#
- SERVER_STREAMING = (False, True)#
- UNARY = (False, False)#
- pw_rpc2.ProtoSource = module | google.protobuf.descriptor.FileDescriptor | google.protobuf.descriptor.ServiceDescriptor#
Represent a union type
E.g. for int | str
- pw_rpc2.DEFAULT_HANDSHAKE_TIMEOUT = 5.0#
Convert a string or number to a floating-point number, if possible.
Calls#
- class pw_rpc2.Call(state: CallState, timeout: float)#
Base class for handles to RPCs.
Using a call as a context manager cancels it on exit if it is still active, which ensures that the server does not keep working on a call that the client abandoned:
with service.StreamThings() as stream: for thing in stream: if is_what_i_wanted(thing): break # The call is cancelled here.
- class pw_rpc2.Reader(state: CallState, timeout: float)#
A call that receives a stream of responses.
Both
ServerStreamingCallandBidirectionalStreamingCallare readers, so functions that only consume responses can annotate their parameter asReader.- __iter__() Iterator[Any]#
Yields responses until the server finishes the stream.
Each response is subject to the call’s default timeout.
- cancel() bool#
Cancels the call, notifying the server.
- Returns:
True if the call was cancelled; False if it had already completed.
- read(timeout: float | None = None) Any | None#
Waits for the next response.
- Returns:
The next response, or
Noneif the server finished the stream.- Raises:
RpcError – The call failed with a protocol error.
RpcTimeout – No response arrived in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- class pw_rpc2.Writer(state: CallState, timeout: float)#
A call that sends a stream of requests.
Both
ClientStreamingCallandBidirectionalStreamingCallare writers, so functions that only send requests can annotate their parameter asWriter.- cancel() bool#
Cancels the call, notifying the server.
- Returns:
True if the call was cancelled; False if it had already completed.
- property status: RpcStatus | None#
The
RpcStatus, orNonewhile active.A call that ended due to a local error, such as a lost connection, has no status.
- write(request: Message | None = None, /, **fields: Any) None#
Sends a request, given as a message or as keyword arguments.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
ValueError – The request is too large for the socket.
RpcError – The call ended with a protocol error.
SocketClosed – The connection is closed.
- class pw_rpc2.UnaryCall(state: CallState, timeout: float)#
A unary RPC.
Calling a unary method client waits for its response. Use
invoke()to obtain aUnaryCallinstead, for example to issue several RPCs before waiting on any.- cancel() bool#
Cancels the call, notifying the server.
- Returns:
True if the call was cancelled; False if it had already completed.
- class pw_rpc2.ServerStreamingCall(state: CallState, timeout: float)#
A server streaming RPC.
Iterate over the call, or call
read(), to receive responses.- __iter__() Iterator[Any]#
Yields responses until the server finishes the stream.
Each response is subject to the call’s default timeout.
- cancel() bool#
Cancels the call, notifying the server.
- Returns:
True if the call was cancelled; False if it had already completed.
- read(timeout: float | None = None) Any | None#
Waits for the next response.
- Returns:
The next response, or
Noneif the server finished the stream.- Raises:
RpcError – The call failed with a protocol error.
RpcTimeout – No response arrived in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- class pw_rpc2.ClientStreamingCall(state: CallState, timeout: float)#
A client streaming RPC.
Send requests with
write(), then callfinish()to end the request stream and receive the response.- cancel() bool#
Cancels the call, notifying the server.
- Returns:
True if the call was cancelled; False if it had already completed.
- finish(timeout: float | None = None) Any#
Ends the request stream and waits for the response.
The server may respond before the request stream ends, in which case this returns that response.
timeoutapplies to waiting for the response after sending the stream end.- Raises:
RpcError – The call failed.
RpcTimeout – The response did not arrive in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- property status: RpcStatus | None#
The
RpcStatus, orNonewhile active.A call that ended due to a local error, such as a lost connection, has no status.
- write(request: Message | None = None, /, **fields: Any) None#
Sends a request, given as a message or as keyword arguments.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
ValueError – The request is too large for the socket.
RpcError – The call ended with a protocol error.
SocketClosed – The connection is closed.
- class pw_rpc2.BidirectionalStreamingCall(state: CallState, timeout: float)#
A bidirectional streaming RPC.
Send requests with
write()and receive responses withread()or by iterating. Callfinish()once all requests are sent; the server may keep responding until it finishes the call.- __iter__() Iterator[Any]#
Yields responses until the server finishes the stream.
Each response is subject to the call’s default timeout.
- cancel() bool#
Cancels the call, notifying the server.
- Returns:
True if the call was cancelled; False if it had already completed.
- finish() None#
Ends the request stream.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
- read(timeout: float | None = None) Any | None#
Waits for the next response.
- Returns:
The next response, or
Noneif the server finished the stream.- Raises:
RpcError – The call failed with a protocol error.
RpcTimeout – No response arrived in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- property status: RpcStatus | None#
The
RpcStatus, orNonewhile active.A call that ended due to a local error, such as a lost connection, has no status.
- write(request: Message | None = None, /, **fields: Any) None#
Sends a request, given as a message or as keyword arguments.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
ValueError – The request is too large for the socket.
RpcError – The call ended with a protocol error.
SocketClosed – The connection is closed.
Errors and status codes#
- class pw_rpc2.RpcStatus(*values)#
The outcome of a pw_rpc2 operation, expressed as what the caller should do next.
Each code maps to one distinct action, so the code alone is enough to decide how to respond. The precise cause of an error is not part of the status: pw_rpc2 logs it where it is detected.
These codes are never sent on the wire. Endpoints exchange more precise error codes, which the receiver converts to one of these. The numeric values may change.
- ABORTED = 8#
The server started the call, then ended it for a reason outside the method’s control. The method may have partly run.
Action: Retry only if the method is idempotent; otherwise, report the failure.
- CANCELLED = 2#
Application code on either side ended the call, explicitly (with Cancel()) or implicitly (for example, by dropping a call handle).
Action: Stop work on the call. Don’t retry automatically: application logic chose to end it.
- CLOSED = 3#
You closed the Client or Server, or the object you used is empty.
Action: Up to you; you closed this call.
- DATA_ERROR = 11#
A message could not be encoded or decoded.
Action: Don’t resend the same message unchanged; fix it or the schema mismatch. What remains of the call depends on where the error occurred:
Local write: nothing was sent, and the call is still open.
Local read: that one message is dropped. A stream stays open, and the next read may succeed.
The server could not decode the request: the call is over.
- DISCONNECTED = 5#
The connection is gone or could not be made, for a reason that a new connection can fix. Whether the peer processed in-flight calls is unknown.
Action: Create a new Client, with backoff. Retry in-flight calls only if they are idempotent. On a server, stop work on the call.
- END_OF_STREAM = 1#
The peer finished its stream and every message it sent has been read. Not a failure. For a client, the RPC finished successfully.
Action: Stop reading.
- MESSAGE_TOO_LARGE = 10#
An outbound message is larger than the transport or reservation allows. Nothing was sent, and the call is still open.
Action: Send a smaller message (for example, split it), or raise the reservation or transport limit.
- OK = 0#
The operation succeeded.
Action: Continue.
- PROTOCOL_ERROR = 12#
An endpoint broke the protocol, the endpoints’ protocol versions are incompatible, or an RPC implementation has a bug. If the error closed the connection, later calls on the same Client also report PROTOCOL_ERROR.
Action: Nothing fixes this at runtime: reconnecting and retrying won’t help. Log or report it; it needs a code or deployment fix.
- RESOURCE_EXHAUSTED = 6#
This endpoint could not allocate memory for the operation. The peer was not involved.
Action: Free local resources (finish or drop other calls, or run fewer at once), then retry. Backing off against the server won’t help.
- UNAVAILABLE = 7#
The server could not take the call right now. The method never ran.
Action: Retry later with backoff. Retrying is safe even for methods that are not idempotent.
- UNIMPLEMENTED = 9#
The server does not offer this method in the form the client expects.
Action: Don’t retry against this server. Fall back (for example, to an older API or a feature-detected path), or fix the deployment or schema mismatch.
- WRITE_CLOSED = 4#
This call’s outbound direction is closed. The call itself may still be open.
Action: Stop writing. If a response or more messages are expected, keep reading.
- exception pw_rpc2.RpcError(
- method: Method,
- status: RpcStatus,
- detail: str = '',
- *,
- protocol_error: ProtocolError | UnknownProtocolError | None = None,
An RPC failed with an error status.
- method#
The RPC that failed.
- detail#
A description of the failure, which may be empty.
- exception pw_rpc2.RpcTimeout(method: Method, timeout: float)#
An RPC operation did not complete before its timeout expired.
Timing out does not end the call, except for unary RPCs invoked by calling the method client directly, whose call object is never exposed.
- method#
The RPC that timed out.
- timeout#
The timeout that expired, in seconds.
- exception pw_rpc2.HandshakeError(message: str, status: RpcStatus = RpcStatus.PROTOCOL_ERROR)#
The connection handshake with the server failed.
- status#
The
RpcStatusfor the failure:RpcStatus.DISCONNECTEDif the socket closed during the handshake, orRpcStatus.PROTOCOL_ERRORif the server sent an invalid reply or did not complete the handshake in time.
- exception pw_rpc2.StreamClosedError#
The client’s request stream is already closed.
Raised when calling
write()orBidirectionalStreamingCall.finish()after the request stream has already been finished or the call has completed.- status#
Always
RpcStatus.WRITE_CLOSED.
- exception pw_rpc2.DecodeError(message: str, status: RpcStatus = RpcStatus.PROTOCOL_ERROR)#
The bytes are not a valid pw_rpc2 packet or protobuf message.
- status#
The
RpcStatusfor the failure:RpcStatus.PROTOCOL_ERRORfor a malformed packet, orRpcStatus.DATA_ERRORfor a payload that could not be decoded as a protobuf message.
Transports#
pw_rpc2.SocketClosed is re-exported from
pw_transport.SocketClosed. Socket interfaces and implementations
(pw_transport.ReliableSocket, pw_transport.framed_tcp, and
pw_transport.forwarding_socket) are documented in the
pw_transport Python reference.
pw_rpc2.aio#
An asyncio pw_rpc2 client.
This mirrors pw_rpc2.Client, with coroutines in place of blocking
operations:
from pw_rpc2 import aio
from pw_transport import framed_tcp
from echo_pb import echo_pb2
async with await aio.Client.connect(
lambda: framed_tcp.connect('localhost', 8000), [echo_pb2]
) as client:
echo = client.rpcs.examples.Echo
# Awaiting a unary method returns its response.
print((await echo.Echo(msg='hello')).msg)
# Server streaming methods return a call to iterate over.
async with echo.Repeat(msg='hi', count=3) as call:
async for response in call:
print(response.msg)
# Client streaming calls are written to, then finished.
async with echo.Collect() as call:
await call.write(msg='one')
await call.write(msg='two')
print((await call.finish()).msg)
# Bidirectional streaming calls are written to and read from.
async with echo.EchoStream() as call:
await call.write(msg='ping')
print((await call.read()).msg)
await call.finish()
Starting a streaming RPC does not block, so streaming method clients return their call directly.
Cancelling a task that is awaiting a unary RPC, as in
await echo.Echo(msg='hello'), cancels the RPC.
Cancelling a task that is awaiting an operation on a call, such as read(),
write(), finish(), or response(), only stops the wait; it does not
cancel the RPC. To cancel the RPC, leave the call’s async with block or
call cancel(). A cancelled write() or finish() may still be sent,
because a packet that is already being sent cannot be recalled, so
asyncio.CancelledError does not mean that the server did not receive the
request.
Client and services#
- class pw_rpc2.aio.Client#
An asyncio client for a pw_rpc2 server.
Create clients with
connect(); there is no public constructor, since connecting requires awaiting the handshake. The client owns itsReliableSocket; closing the client closes the socket and ends any active calls withCLOSED.Packets are received on a background thread and delivered to the event loop, and sent from a dedicated thread so that socket backpressure never blocks the event loop.
- add_services(
- protos: Iterable[ModuleType | FileDescriptor | ServiceDescriptor],
Creates service clients for more services.
A service with the same name as an existing service replaces it.
- Raises:
TypeError – Something in
protosdoes not describe services.ValueError – Services or methods with different names have the same ID, or a service and a package share a name.
- async classmethod connect(
- target: ReliableSocket | Callable[[], ReliableSocket],
- protos: Iterable[ModuleType | FileDescriptor | ServiceDescriptor] = (),
- *,
- default_timeout: float | None = None,
- handshake_timeout: float = 5.0,
Connects (if given a callable) and performs the server handshake.
- Parameters:
target – A connected
ReliableSocket(which the client takes ownership of) or a zero-argument callable returning one, which is called on a worker thread.protos – Generated protobuf modules or descriptors of the services to create service clients for.
default_timeout – The default for how long operations wait for a response from the server, in seconds;
Nonewaits forever.handshake_timeout – How long to wait for the server to reply to the connection handshake, in seconds.
- Raises:
HandshakeError – The server did not complete the handshake.
OSError – Opening a socket through
targetfailed.TypeError – Something in
protosdoes not describe services.ValueError – Services or methods with different names have the same ID, a service and a package share a name, or a timeout is negative.
- property default_timeout: float | None#
How long operations wait for a response by default, in seconds.
Nonewaits forever.
- methods() Iterator[MethodClient]#
Yields every method client across all registered services.
- property rpcs: Services[MethodClient]#
The service clients, e.g.
client.rpcs.examples.Echo.
- class pw_rpc2.aio.MethodClient(client: Client, method: Method)#
Invokes an RPC method.
For unary methods, calling the method client returns a coroutine that starts the RPC and produces the response. For streaming methods, it starts the RPC and returns its call.
The
rpc2_timeoutkeyword argument sets the call’s timeout. It has a prefix so that it does not collide with a request field namedtimeout; a field namedrpc2_timeoutcan only be set by passing a message.- property descriptor: MethodDescriptor#
The protobuf
MethodDescriptorfor this method.
- invoke( ) Call#
Starts the RPC without waiting for a response.
This never blocks: the packet that starts the RPC is sent in the background. If sending it fails, the call ends with the error, which the call’s next operation (e.g.
read(),write(), orresponse()) raises.- Parameters:
request – The request message; streaming requests are instead sent with the call’s
write()method.rpc2_timeout – Default timeout for waiting on a response from the server, in seconds.
Noneuses the client’s default.**fields – Request fields, as an alternative to
request.
- Returns:
A call object whose type depends on the RPC type.
- Raises:
TypeError – The request is invalid.
ValueError – A field name is not in the request type, the request is too large for the socket, or the timeout is negative.
DecodeError – A malformed packet closed the connection.
SocketClosed – The connection was already closed.
- property type: MethodType#
The method’s
MethodTypestreaming mode.
Calls#
- class pw_rpc2.aio.Call(client: Client, state: CallState, timeout: float)#
Base class for handles to RPCs.
Using a call as an async context manager cancels it on exit if it is still active.
- class pw_rpc2.aio.Reader(client: Client, state: CallState, timeout: float)#
A call that receives a stream of responses.
Both
ServerStreamingCallandBidirectionalStreamingCallare readers, so functions that only consume responses can annotate their parameter asReader.- async __aiter__() AsyncIterator[Any]#
Yields responses until the server finishes the stream.
Each response is subject to the call’s default timeout.
- cancel() bool#
Cancels the call, notifying the server in the background.
- Returns:
True if the call was cancelled; False if it had already completed.
- async read(timeout: float | None = None) Any | None#
Waits for the next response.
- Returns:
The next response, or
Noneif the server finished the stream.- Raises:
RpcError – The call failed with a protocol error.
RpcTimeout – No response arrived in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- class pw_rpc2.aio.Writer(client: Client, state: CallState, timeout: float)#
A call that sends a stream of requests.
Both
ClientStreamingCallandBidirectionalStreamingCallare writers, so functions that only send requests can annotate their parameter asWriter.- cancel() bool#
Cancels the call, notifying the server in the background.
- Returns:
True if the call was cancelled; False if it had already completed.
- property status: RpcStatus | None#
The
RpcStatus, orNonewhile active.A call that ended due to a local error, such as a lost connection, has no status.
- async write(request: Message | None = None, /, **fields: Any) None#
Sends a request, given as a message or as keyword arguments.
If the awaiting task is cancelled, the request may still be sent.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
ValueError – The request is too large for the socket.
RpcError – The call ended with a protocol error.
SocketClosed – The connection is closed.
- class pw_rpc2.aio.UnaryCall(client: Client, state: CallState, timeout: float)#
A unary RPC, as returned by
MethodClient.invoke().- cancel() bool#
Cancels the call, notifying the server in the background.
- Returns:
True if the call was cancelled; False if it had already completed.
- async response(timeout: float | None = None) Any#
Waits for and returns the response.
- Raises:
RpcError – The call failed.
RpcTimeout – The response did not arrive in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- class pw_rpc2.aio.ServerStreamingCall(client: Client, state: CallState, timeout: float)#
A server streaming RPC; iterate over it to receive responses.
- async __aiter__() AsyncIterator[Any]#
Yields responses until the server finishes the stream.
Each response is subject to the call’s default timeout.
- cancel() bool#
Cancels the call, notifying the server in the background.
- Returns:
True if the call was cancelled; False if it had already completed.
- async read(timeout: float | None = None) Any | None#
Waits for the next response.
- Returns:
The next response, or
Noneif the server finished the stream.- Raises:
RpcError – The call failed with a protocol error.
RpcTimeout – No response arrived in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- class pw_rpc2.aio.ClientStreamingCall(client: Client, state: CallState, timeout: float)#
A client streaming RPC.
Send requests with
write(), then awaitfinish()to end the request stream and receive the response.- cancel() bool#
Cancels the call, notifying the server in the background.
- Returns:
True if the call was cancelled; False if it had already completed.
- async finish(timeout: float | None = None) Any#
Ends the request stream and waits for the response.
The server may respond before the request stream ends, in which case this returns that response.
timeoutapplies to waiting for the response after sending the stream end.- Raises:
RpcError – The call failed.
RpcTimeout – The response did not arrive in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- property status: RpcStatus | None#
The
RpcStatus, orNonewhile active.A call that ended due to a local error, such as a lost connection, has no status.
- async write(request: Message | None = None, /, **fields: Any) None#
Sends a request, given as a message or as keyword arguments.
If the awaiting task is cancelled, the request may still be sent.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
ValueError – The request is too large for the socket.
RpcError – The call ended with a protocol error.
SocketClosed – The connection is closed.
- class pw_rpc2.aio.BidirectionalStreamingCall(client: Client, state: CallState, timeout: float)#
A bidirectional streaming RPC.
Send requests with
write()and receive responses withread()or by iterating. Awaitfinish()once all requests are sent.- async __aiter__() AsyncIterator[Any]#
Yields responses until the server finishes the stream.
Each response is subject to the call’s default timeout.
- cancel() bool#
Cancels the call, notifying the server in the background.
- Returns:
True if the call was cancelled; False if it had already completed.
- async finish() None#
Ends the request stream.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
- async read(timeout: float | None = None) Any | None#
Waits for the next response.
- Returns:
The next response, or
Noneif the server finished the stream.- Raises:
RpcError – The call failed with a protocol error.
RpcTimeout – No response arrived in time.
DecodeError – The response or an incoming packet was malformed.
SocketClosed – The connection was lost.
- property status: RpcStatus | None#
The
RpcStatus, orNonewhile active.A call that ended due to a local error, such as a lost connection, has no status.
- async write(request: Message | None = None, /, **fields: Any) None#
Sends a request, given as a message or as keyword arguments.
If the awaiting task is cancelled, the request may still be sent.
- Raises:
StreamClosedError – The call is already complete or the request stream is already finished.
ValueError – The request is too large for the socket.
RpcError – The call ended with a protocol error.
SocketClosed – The connection is closed.