FileChannel#
- class maize.core.channels.FileChannel(mode: Literal['copy', 'link', 'move'] = 'copy')[source]#
Bases:
Channel
[list
[Path
] |dict
[Any
,Path
] |Path
]A communication channel for data in the form of files. Files must be represented by Path objects, and can either be passed alone, as a list, or as a dictionary.
When sending a file, it is first transferred (depending on mode) to an escrow directory specific to the channel (typically a temporary directory). Upon calling receive, this file is transferred to an input-directory for the receiving node.
- Parameters:
mode – Whether to
copy
(default),link
, ormove
files from node to node.
See also
DataChannel
Channel for arbitrary serializable data
Methods
__init__
([mode])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)Load a file into the channel without explicitly sending.
receive
([timeout])Receive an item.
send
(item[, timeout])Send an item.
setup
(destination)Setup the file channel directories.
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[list[Path] | dict[Any, Path] | Path] [source]#
Flush the contents of the channel.
- Parameters:
timeout – The timeout for item retrieval
- Returns:
List with a paths to a file in the destination directory or an empty list. This is to be consistent with the signature of DataChannel.
- Return type:
list[_FilePathType]
- kill() None [source]#
Kills the channel, called at network shutdown and ensures no orphaned processes.
- preload(items: list[Path] | dict[Any, Path] | Path) None [source]#
Load a file into the channel without explicitly sending.
- receive(timeout: float | None = None) list[Path] | dict[Any, Path] | Path | 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: list[Path] | dict[Any, Path] | Path, 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