quantlab.utils.progress.CallbackProgressReporter#

class quantlab.utils.progress.CallbackProgressReporter(callback)[source]#

Bases: ProgressReporter

Reporter that forwards every event to a function you supply.

Use it for consumers in the same process, such as a terminal user interface: pass a function that pushes each event onto a queue, and you receive structured counts instead of a drawn progress bar. The function’s return value is ignored. If it raises, the loop logs a warning for that event and continues, so a callback that fails on every batch logs on every batch and the problem stays visible.

Parameters:
callbackCallable[[ProgressEvent], None]

Called once per event with the ProgressEvent.

Examples

>>> events = []
>>> reporter = CallbackProgressReporter(events.append)
>>> reporter.emit(ProgressEvent(kind="run_started", vendor="x", total=3))
>>> events[0].total
3
emit(event)[source]#

Pass event to the callback and discard its result.

Parameters:
eventProgressEvent

The event to forward.

Examples

>>> events = []
>>> reporter = CallbackProgressReporter(events.append)
>>> reporter.emit(ProgressEvent(kind="cancelled", vendor="tiingo"))
>>> events[-1].kind
'cancelled'