pyworkflow.utils.retry_streaming module
- pyworkflow.utils.retry_streaming.is_sqlite_lock_error(exc: Exception) bool[source]
Return True if exc is a SQLite OperationalError indicating locked/busy DB.
- pyworkflow.utils.retry_streaming.refreshStreamState(setObj) None[source]
Update the in-memory stream state of a Set from the database.
Uses safeIsStreamOpen() to read the current state from an independent connection, then patches the in-memory _streamState attribute so that subsequent setObj.isStreamOpen() calls return the fresh value without needing loadAllProperties().
- pyworkflow.utils.retry_streaming.retry_on_sqlite_lock(max_attempts: int = 15, initial_delay: float = 0.25, backoff_factor: float = 1.7, max_delay: float = 10, jitter: float = 0.05, log=None, predicate=<function is_sqlite_lock_error>)[source]
Decorator that retries the wrapped function when SQLite signals lock/busy.
- Behavior:
Exponential backoff with small jitter to avoid retry synchronization.
Only retries when predicate(exc) is True (i.e., lock/busy by default).
Propagates any non-retriable exceptions immediately.
If max attempts are exhausted, re-raises the original exception.
- Parameters:
max_attempts Max number of tries (including the first call). initial_delay Initial sleep before the first retry (seconds). backoff_factor Multiply delay on each retry. max_delay Cap the delay (seconds). jitter Random noise added to delay (seconds). log Optional logger (e.g., logging.getLogger(__name__)). predicate Function deciding whether the exception should be retried.
- pyworkflow.utils.retry_streaming.safeIsStreamOpen(setObj) bool[source]
Check if a Set’s stream is open using an independent SQLite connection.
Opens a short-lived, read-only connection to the Set’s backing SQLite file and queries ONLY the _streamState property. This avoids:
Reusing the Set’s internal mapper connection (no mapper contention)
Holding protocol-level locks during the check
The heavyweight loadAllProperties() call that reads ALL properties
Safe to call from any thread while the producer may be writing concurrently. Returns False (stream closed) on any error, since a missing/corrupt DB means no more data is coming.