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, or move files from node to node.

See also

DataChannel

Channel for arbitrary serializable data

__init__(mode: Literal['copy', 'link', 'move'] = 'copy') None[source]#

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

active

Returns whether the channel is active.

ready

Returns whether the channel is ready to receive from.

size

Returns the current approximate size of the buffer

property active: bool#

Returns whether the channel is active.

close() None[source]#

Closes the channel.

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.

property ready: bool#

Returns whether the channel is ready to receive from.

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

setup(destination: Path) None[source]#

Setup the file channel directories.

Parameters:

destination – Path to the destination directory for the input port

property size: int#

Returns the current approximate size of the buffer