prpc.Stream

class prpc.stream.Stream(id, loop)

Demultiplexed data stream.

Represents a (possibly bidirectional) data flow between RPC client and called method.

Can be used as a async iterator, e.g. simple echo implementation:

async for msg in stream:
    await stream.send(msg)
is_writable

Returns True if stream accepts ‘send’ requests.

is_readable

Returns True if stream accepts ‘receive’ requests.

is_open

Return True if stream is open.

is_closed

Return True if stream is closed.

data_available

Check if there are any messages immediately available.

on_write

Get write signal instance.

on_close

Get close signal instance.

coroutine receive(timeout=None)

Read a data chunk from the stream.

Note

Shoudn’t be ever awaited in parallel from different coroutines.

Returns:Received value or None (None means that stream is closed).
coroutine send(data)

Send a message to a remote stream.

Parameters:data – Data chunk to send.
coroutine close()

Close the stream and notify the peer.

coroutine feed(data, timeout=None)

Feed a new ‘input’ message into stream.

Warning

Should not be called by client code, used by library internally.

Parameters:
  • data – Unpacked message content.
  • timeout – Timeout (in seconds).
Returns:

True if feed was successfull, False otherwise (message is dropped).

open(mode)

Open a stream in a given mode.

Warning

Should not be called by client code, used by library internally.

Parameters:mode – Stream open mode (r/w/rw).
close_sync()

Close the stream synchronously.

Implement ‘forced’ closes, when there is no need to notify the peer (close received from peer, call finished, connection closed etc).

Warning

Should not be called by client code, used by library internally.