Track progress by iterating over a sequence. You can also track progress of an iterable, which might require that you additionally specify ``total``. Args: sequence (Iterable[ProgressType]): Values you want to iterate over and track progress. total: (float,
(
self,
sequence: Iterable[ProgressType],
total: Optional[float] = None,
completed: int = 0,
task_id: Optional[TaskID] = None,
description: str = "Working...",
update_period: float = 0.1,
)
| 1190 | self.stop() |
| 1191 | |
| 1192 | def track( |
| 1193 | self, |
| 1194 | sequence: Iterable[ProgressType], |
| 1195 | total: Optional[float] = None, |
| 1196 | completed: int = 0, |
| 1197 | task_id: Optional[TaskID] = None, |
| 1198 | description: str = "Working...", |
| 1199 | update_period: float = 0.1, |
| 1200 | ) -> Iterable[ProgressType]: |
| 1201 | """Track progress by iterating over a sequence. |
| 1202 | |
| 1203 | You can also track progress of an iterable, which might require that you additionally specify ``total``. |
| 1204 | |
| 1205 | Args: |
| 1206 | sequence (Iterable[ProgressType]): Values you want to iterate over and track progress. |
| 1207 | total: (float, optional): Total number of steps. Default is len(sequence). |
| 1208 | completed (int, optional): Number of steps completed so far. Defaults to 0. |
| 1209 | task_id: (TaskID): Task to track. Default is new task. |
| 1210 | description: (str, optional): Description of task, if new task is created. |
| 1211 | update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1. |
| 1212 | |
| 1213 | Returns: |
| 1214 | Iterable[ProgressType]: An iterable of values taken from the provided sequence. |
| 1215 | """ |
| 1216 | if total is None: |
| 1217 | total = float(length_hint(sequence)) or None |
| 1218 | |
| 1219 | if task_id is None: |
| 1220 | task_id = self.add_task(description, total=total, completed=completed) |
| 1221 | else: |
| 1222 | self.update(task_id, total=total, completed=completed) |
| 1223 | |
| 1224 | if self.live.auto_refresh: |
| 1225 | with _TrackThread(self, task_id, update_period) as track_thread: |
| 1226 | for value in sequence: |
| 1227 | yield value |
| 1228 | track_thread.completed += 1 |
| 1229 | else: |
| 1230 | advance = self.advance |
| 1231 | refresh = self.refresh |
| 1232 | for value in sequence: |
| 1233 | yield value |
| 1234 | advance(task_id, 1) |
| 1235 | refresh() |
| 1236 | |
| 1237 | def wrap_file( |
| 1238 | self, |