MCPcopy Create free account
hub / github.com/espnet/espnet / _submit_tasks

Function _submit_tasks

espnet3/parallel/parallel.py:347–378  ·  view source on GitHub ↗

Submit job for parallel_map and parallel_for. - Creates/reuses a client (and handles its lifecycle if internal). - Registers the setup plugin (client- and worker-side). - Performs client-side conflict checks. - Wraps the function to inject worker env. - Submits tasks and yields

(
    func: Callable[[Any], Any],
    iterable: Iterable[Any],
    client: Optional[Client] = None,
    setup_fn: Optional[Callable[[], dict]] = None,
    **kwargs: Any,
)

Source from the content-addressed store, hash-verified

345
346@contextmanager
347def _submit_tasks(
348 func: Callable[[Any], Any],
349 iterable: Iterable[Any],
350 client: Optional[Client] = None,
351 setup_fn: Optional[Callable[[], dict]] = None,
352 **kwargs: Any,
353):
354 """Submit job for parallel_map and parallel_for.
355
356 - Creates/reuses a client (and handles its lifecycle if internal).
357 - Registers the setup plugin (client- and worker-side).
358 - Performs client-side conflict checks.
359 - Wraps the function to inject worker env.
360 - Submits tasks and yields (client, futures).
361 """
362 _ensure_dask()
363 internal = client is None
364 if internal:
365 ctx = get_client(setup_fn=setup_fn)
366 client_cm = ctx
367 client = ctx.__enter__()
368 elif setup_fn is not None:
369 plugin = DictReturnWorkerPlugin(setup_fn)
370 getattr(client, "register_worker_plugin")(plugin, name="env")
371
372 try:
373 wrapped_func = wrap_func_with_worker_env(func)
374 futures = client.map(wrapped_func, iterable, **kwargs)
375 yield client, futures
376 finally:
377 if internal:
378 client_cm.__exit__(None, None, None)
379
380
381@typechecked

Callers 2

parallel_mapFunction · 0.85
parallel_forFunction · 0.85

Calls 6

_ensure_daskFunction · 0.85
get_clientFunction · 0.85
__enter__Method · 0.45
__exit__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…