MCPcopy Create free account
hub / github.com/modelscope/modelscope / track_progress

Function track_progress

modelscope/preprocessors/cv/util.py:79–107  ·  view source on GitHub ↗

Track the progress of tasks execution with a progress bar. Tasks are done with a simple for-loop. Args: func (callable): The function to be applied to each task. tasks (list or tuple[Iterable, int]): A list of tasks or (tasks, total num). bar_width (int):

(func, tasks, bar_width=50, file=sys.stdout, **kwargs)

Source from the content-addressed store, hash-verified

77
78
79def track_progress(func, tasks, bar_width=50, file=sys.stdout, **kwargs):
80 """Track the progress of tasks execution with a progress bar.
81 Tasks are done with a simple for-loop.
82 Args:
83 func (callable): The function to be applied to each task.
84 tasks (list or tuple[Iterable, int]): A list of tasks or
85 (tasks, total num).
86 bar_width (int): Width of progress bar.
87 Returns:
88 list: The task results.
89 """
90 if isinstance(tasks, tuple):
91 assert len(tasks) == 2
92 assert isinstance(tasks[0], Iterable)
93 assert isinstance(tasks[1], int)
94 task_num = tasks[1]
95 tasks = tasks[0]
96 elif isinstance(tasks, Iterable):
97 task_num = len(tasks)
98 else:
99 raise TypeError(
100 '"tasks" must be an iterable object or a (iterator, int) tuple')
101 prog_bar = ProgressBar(task_num, bar_width, file=file)
102 results = []
103 for task in tasks:
104 results.append(func(task, **kwargs))
105 prog_bar.update()
106 prog_bar.file.write('\n')
107 return results

Callers 1

cvt2framesMethod · 0.85

Calls 5

updateMethod · 0.95
ProgressBarClass · 0.85
funcFunction · 0.85
appendMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…