DataChannel#
- class maize.core.channels.DataChannel(size: int)[source]#
Bases:
Channel
[T
]A communication channel for data in the form of python objects.
Any item sent needs to be serializable using dill.
- Parameters:
size – Size of the item queue
See also
FileChannel
Channel for files
Methods
__init__
(size)close
()Closes the channel.
flush
([timeout])Flush the contents of the channel.
kill
()Kills the channel, called at network shutdown and ensures no orphaned processes.
preload
(items)Pre-load the channel with a serialized item.
receive
([timeout])Receive an item.
send
(item[, timeout])Send an item.
Attributes
Returns whether the channel is active.
Returns whether the channel is ready to receive from.
Returns the current approximate size of the buffer
- flush(timeout: float = 0.5) list[T] [source]#
Flush the contents of the channel.
- Parameters:
timeout – The timeout for item retrieval
- Returns:
List of unserialized channel contents
- Return type:
list[T]
- kill() None [source]#
Kills the channel, called at network shutdown and ensures no orphaned processes.
- preload(items: list[bytes] | bytes) None [source]#
Pre-load the channel with a serialized item. Used by restarts.
- Parameters:
items – Serialized items to pre-load the channel with
- receive(timeout: float | None = None) T | None [source]#
Receive an item.
- Parameters:
timeout – Timeout in seconds to wait for an item
- Returns:
The received item, or
None
if the channel is empty- Return type:
T | None
- send(item: T, timeout: float | None = None) None [source]#
Send an item.
Will attempt to send an item of any type into a channel, potentially blocking if the channel is full.
- Parameters:
item – Item to send
timeout – Timeout in seconds to wait for space in the channel
- Raises:
ChannelFull – If the channel is already full