quantlab.utils.progress.ProgressReporter#
- class quantlab.utils.progress.ProgressReporter[source]#
Bases:
ABCAbstract destination for progress events.
Subclasses implement
emit. The loop calls it once per event and ignores the return value, so a reporter cannot stop a run. That is intentional: stopping goes throughCancelToken, so a reporter that only wants to log can never halt a multi-hour download by accident.Examples
>>> class PrintReporter(ProgressReporter): ... def emit(self, event: ProgressEvent) -> None: ... print(event.kind, event.completed, event.total)
- close()[source]#
Release any resource
emitopened. The default does nothing.Examples
>>> class FileReporter(ProgressReporter): ... def __init__(self, path): ... self._handle = open(path, "a") ... def emit(self, event: ProgressEvent) -> None: ... print(event.kind, file=self._handle) ... def close(self) -> None: ... self._handle.close()
- abstractmethod emit(event)[source]#
Receive one event.
Implementations should not raise. If one does, the calling loop logs the exception and carries on, so a bug in reporting cannot end a long download.
- Parameters:
- eventProgressEvent
The event to handle.
Examples
>>> class ListReporter(ProgressReporter): ... def __init__(self): ... self.events = [] ... def emit(self, event: ProgressEvent) -> None: ... self.events.append(event)