pipeloom.writer¶
pipeloom.writer ¶
writer.py¶
The single SQLite writer thread. It:
- Opens and owns the only SQLite connection (configured for WAL).
- Consumes message objects from a thread-safe Queue.
- Writes task status/progress to SQLite (optional).
- Updates/removes Rich per-task progress bars safely.
Why a single writer?¶
SQLite allows multiple writers serially, but a single connection and a single owning thread is the least surprising, highest-reliability approach. It also avoids cross-thread connection misuse, which is a common source of bugs.
SQLiteWriter ¶
SQLiteWriter(db_path: Path, msg_q: Queue[Msg], *, wal: bool = True, store_task_status: bool = True, task_progress: Progress | None = None, task_bar_map: dict[int, TaskID] | None = None)
Bases: Thread
Dedicated thread that exclusively writes to SQLite and manages per-task bars.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path
|
Path to the SQLite database file (or ':memory:'). |
required |
msg_q
|
Queue[Msg]
|
Thread-safe queue from which this writer consumes message objects. |
required |
wal
|
bool
|
Whether to enable WAL on file-backed databases. |
True
|
store_task_status
|
bool
|
Toggle persistence of task status into the |
True
|
task_progress
|
Progress | None
|
Rich Progress manager used for per-task bars (transient). |
None
|
task_bar_map
|
dict[int, TaskID] | None
|
Pre-registered mapping: task_id -> Rich TaskID (prevents render races). |
None
|
Source code in pipeloom/writer.py
run ¶
Lifecycle: - open connection - initialize schema (optional) - consume messages until SENTINEL arrives - checkpoint and close