File Writer
- class gpype.backend.sinks.base.file_writer.FileWriter[source]
Bases:
INodeAbstract 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.
- __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:
- Return type:
- Returns:
Empty dictionary as this is a sink node with no outputs.
- Raises:
RuntimeError – If sampling rate is not provided in port context.
- abstract property file_extension
Return the file extension for this writer type.
- Returns:
File extension including the dot (e.g., ‘.csv’, ‘.hdf5’).