Skip to main content

Channel

A shared-memory channel handle (process-private).

Usage

Source

Channel()

Create the host side with Channel.create(), which spawns the peer. The peer side attaches with Channel._attach(), as python -m pymizu.child does. Handles do not survive fork().

Threading: a side belongs to one thread at a time. Call its verbs (send(), recv(), their batch forms) from one thread only; a second verb from another thread raises ConcurrentUseError. Blocking and async receives are likewise exclusive on a side: a blocking receive while a recv_async() consumer is active raises it too, from any thread but the consumer’s event loop, whose own receives can never race it. Two-way traffic from two threads needs two channels. Teardown is the exception: destroy() is safe from any thread.

Attributes

Name Description
token The join token for the peer’s attach.

Functions

Name Description
__aiter__() Yield received values until CLOSED or PEER_GONE.
__iter__() Iterate over received payloads until CLOSED or PEER_GONE.
alive() True while the peer process is alive.
close() Close the channel in an orderly way.
create() Create a channel and spawn its peer.
destroy() Tear down the handle immediately, without the close handshake.
info() A read-only snapshot of the channel’s state (dict).
recv() Receive one value.
recv_async() Return an asyncio.Future that resolves with the next value.
recv_batch() Receive up to n values in one call.
recv_batch_async() Return an asyncio.Future for a list of received values.
send() Send one value.
send_batch() Send several values in one call.