Method: rich.progress.Progress.track
Calls: 3, Exceptions: 0, Paths: 2Back
Path 1: 2 calls (0.67)
['foo', 'bar', 'baz'] (2)
None (2)
None (2)
'test' (2)
0.1 (2)
'foo' (2) 'bar' (2) 'baz' (2)
1def track(
2 self,
3 sequence: Union[Iterable[ProgressType], Sequence[ProgressType]],
4 total: Optional[float] = None,
5 task_id: Optional[TaskID] = None,
6 description: str = "Working...",
7 update_period: float = 0.1,
8 ) -> Iterable[ProgressType]:
9 """Track progress by iterating over a sequence.
10
11 Args:
12 sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress.
13 total: (float, optional): Total number of steps. Default is len(sequence).
14 task_id: (TaskID): Task to track. Default is new task.
15 description: (str, optional): Description of task, if new task is created.
16 update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
17
18 Returns:
19 Iterable[ProgressType]: An iterable of values taken from the provided sequence.
20 """
21
22 task_total: Optional[float] = None
23 if total is None:
24 if isinstance(sequence, Sized):
25 task_total = float(len(sequence))
26 else:
27 task_total = total
28
29 if task_id is None:
30 task_id = self.add_task(description, total=task_total)
31 else:
32 self.update(task_id, total=task_total)
33
34 if self.live.auto_refresh:
35 with _TrackThread(self, task_id, update_period) as track_thread:
36 for value in sequence:
37 yield value
38 track_thread.completed += 1
39 else:
40 advance = self.advance
41 refresh = self.refresh
42 for value in sequence:
43 yield value
44 advance(task_id, 1)
45 refresh()
Path 2: 1 calls (0.33)
['foo', 'bar', 'baz'] (1)
None (1)
None (1)
'test' (1)
0.1 (1)
'foo' (1) 'bar' (1) 'baz' (1)
1def track(
2 self,
3 sequence: Union[Iterable[ProgressType], Sequence[ProgressType]],
4 total: Optional[float] = None,
5 task_id: Optional[TaskID] = None,
6 description: str = "Working...",
7 update_period: float = 0.1,
8 ) -> Iterable[ProgressType]:
9 """Track progress by iterating over a sequence.
10
11 Args:
12 sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress.
13 total: (float, optional): Total number of steps. Default is len(sequence).
14 task_id: (TaskID): Task to track. Default is new task.
15 description: (str, optional): Description of task, if new task is created.
16 update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
17
18 Returns:
19 Iterable[ProgressType]: An iterable of values taken from the provided sequence.
20 """
21
22 task_total: Optional[float] = None
23 if total is None:
24 if isinstance(sequence, Sized):
25 task_total = float(len(sequence))
26 else:
27 task_total = total
28
29 if task_id is None:
30 task_id = self.add_task(description, total=task_total)
31 else:
32 self.update(task_id, total=task_total)
33
34 if self.live.auto_refresh:
35 with _TrackThread(self, task_id, update_period) as track_thread:
36 for value in sequence:
37 yield value
38 track_thread.completed += 1
39 else:
40 advance = self.advance
41 refresh = self.refresh
42 for value in sequence:
43 yield value
44 advance(task_id, 1)
45 refresh()