Skip to content

Utilities

Helpers for scripts and applications that use ropt live in ropt.utils. This page covers the lower-level component utilities.

Concurrency

run_concurrent runs blocking calls on dedicated threads rather than on the event loop's shared thread pool. The simple API uses it to drive many optimizations at once; a workflow that has to run blocking coordinators of its own can use it directly.

ropt.components.concurrency.run_concurrent

run_concurrent(
    jobs: Sequence[Callable[[], _T]],
    limit: int | None = None,
) -> list[_T]

Run blocking jobs concurrently on dedicated threads and collect results.

Each job runs on its own thread, so the number of jobs that run at once is not capped by any shared thread pool; limit optionally bounds how many run simultaneously. The first job to raise makes its exception propagate as soon as it is observed (fail-fast): jobs that have not started yet are skipped, while any already running are abandoned, since a Python thread cannot be stopped from the outside.

Parameters:

Name Type Description Default
jobs Sequence[Callable[[], _T]]

The zero-argument callables to run, one result each.

required
limit int | None

The maximum number to run at once, or None for no limit.

None

Returns:

Type Description
list[_T]

The job results, in the order of jobs.