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,
)
| 345 | |
| 346 | @contextmanager |
| 347 | def _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 |
no test coverage detected
searching dependent graphs…