MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / multithead_execute

Function multithead_execute

eval_code/recons/models/moge/utils/tools.py:224–249  ·  view source on GitHub ↗
(inputs: List[Any], num_workers: int, pbar = None)

Source from the content-addressed store, hash-verified

222
223
224def multithead_execute(inputs: List[Any], num_workers: int, pbar = None):
225 from concurrent.futures import ThreadPoolExecutor
226 from contextlib import nullcontext
227 from tqdm import tqdm
228
229 if pbar is not None:
230 pbar.total = len(inputs) if hasattr(inputs, '__len__') else None
231 else:
232 pbar = tqdm(total=len(inputs) if hasattr(inputs, '__len__') else None)
233
234 def decorator(fn: Callable):
235 with (
236 ThreadPoolExecutor(max_workers=num_workers) as executor,
237 pbar
238 ):
239 pbar.refresh()
240 @catch_exception
241 @suppress_traceback
242 def _fn(input):
243 ret = fn(input)
244 pbar.update()
245 return ret
246 executor.map(_fn, inputs)
247 executor.shutdown(wait=True)
248
249 return decorator
250
251
252def suppress_traceback(fn):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected