File Writer

class gpype.backend.sinks.base.file_writer.FileWriter[source]

Bases: INode

Abstract base class for threaded file writers.

Implements a file writer that operates in a separate background thread to prevent blocking the main signal processing pipeline. Data is queued and written asynchronously to maintain real-time performance.

Subclasses must implement format-specific file operations.

class Configuration[source]

Bases: Configuration

Configuration class for FileWriter parameters.

class Keys[source]

Bases: Keys

Configuration keys for file writer settings.

FILE_NAME = 'file_name'

File name configuration key

__init__(file_name, **kwargs)[source]

Initialize the file writer with specified filename.

Parameters:
  • file_name (str) – Base filename for data output. A timestamp will be automatically appended.

  • **kwargs – Additional arguments passed to parent INode class.

start()[source]

Start the file writer and initialize background thread.

Generates the output file path with timestamp and starts the background worker thread for asynchronous writing. The actual file opening is deferred to setup() when port context is available.

Raises:

ValueError – If the file extension is invalid for this writer.

stop()[source]

Stop the file writer and clean up resources.

Signals the background thread to stop, waits for it to finish processing remaining data, and properly closes the file. Ensures all queued data is written before stopping.

setup(data, port_context_in)[source]

Setup method called before processing begins.

Extracts sampling rate from port context and opens the output file using the format-specific implementation.

Parameters:
  • data (dict[str, ndarray]) – Dictionary of input data arrays from connected ports.

  • port_context_in (dict[str, dict]) – Context information from input ports.

Return type:

dict[str, dict]

Returns:

Empty dictionary as this is a sink node with no outputs.

Raises:

RuntimeError – If sampling rate is not provided in port context.

step(data)[source]

Process incoming data by queuing it for background writing.

Parameters:

data (dict[str, ndarray]) – Dictionary containing input data arrays. Uses the default input port to retrieve data for writing.

Return type:

dict[str, ndarray]

Returns:

Empty dictionary as this is a sink node with no outputs.

abstract property file_extension

Return the file extension for this writer type.

Returns:

File extension including the dot (e.g., ‘.csv’, ‘.hdf5’).