pool
¶
Async path-→-tensor prefetcher for the Evaluator.
Hides video-decode latency behind metric compute by running a small
thread pool of decoders that fill a bounded queue. One :class:VideoPool
is owned by the Evaluator per evaluate(samples=...) call; workers
consume via :meth:VideoPool.get. Decode order is non-deterministic;
each yielded item carries its original input index so consumers can
write back into a result list in input order.
Pool sizing: max_size = prefetch_factor * num_workers.
Classes¶
fastvideo.eval.pool.VideoPool
¶
Bounded prefetch queue feeding decoded samples to consumers.
Use as a context manager so loader threads are always cleaned up::
with VideoPool(samples, loader_threads=1, max_size=4) as pool:
while True:
item = pool.get()
if item is None:
break
idx, decoded = item
results[idx] = worker.evaluate(**decoded)
Source code in fastvideo/eval/pool.py
Functions¶
fastvideo.eval.pool.VideoPool.get
¶
Pop the next decoded (idx, sample).
Returns None when all input samples have been consumed.
Polls in 0.1 s slices so extra consumer threads (when
len(samples) < num_workers) wake up periodically to
re-check _consumed and exit cleanly — without the poll,
a blocking _ready_q.get(timeout=None) deadlocks because
the loaders are already done. Re-raises any exception caught
in a loader thread on the consumer's stack so callers don't
hang on a dead loader. Thread-safe: multiple consumer threads
may share one pool.