from typing import Any, NewType, Optional import rich.progress TaskID = NewType("TaskID", int) class MultiprocessProgress(rich.progress.Progress): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) def add_task( self, description: str, task_id: str, start: bool = True, total: Optional[float] = 100.0, completed: int = 0, visible: bool = True, **fields: Any, ) -> TaskID: """Add a new 'task' to the Progress display. Args: description (str): A description of the task. start (bool, optional): Start the task immediately (to calculate elapsed time). If set to False, you will need to call `start` manually. Defaults to True. total (float, optional): Number of total steps in the progress if known. Set to None to render a pulsing animation. Defaults to 100. completed (int, optional): Number of steps completed so far. Defaults to 0. visible (bool, optional): Enable display of the task. Defaults to True. **fields (str): Additional data fields required for rendering. Returns: TaskID: An ID you can use when calling `update`. """ with self._lock: task = rich.job_progress.Task( task_id, description, total, completed, visible=visible, fields=fields, _get_time=self.get_time, _lock=self._lock, ) self._tasks[task_id] = task if start: self.start_task(task_id) self.refresh() return task_id