rslearn.utils.mp¶
mp ¶
Multi-processing utilities.
StarImapUnorderedWrapper ¶
Wrapper for a function to implement star_imap_unordered.
A kwargs dict is passed to this wrapper, which then calls the underlying function with the unwrapped kwargs.
Source code in rslearn/utils/mp.py
star_imap_unordered ¶
star_imap_unordered(p: Pool, fn: Callable[..., Any], kwargs_list: list[dict[str, Any]]) -> IMapIterator
Wrapper for Pool.imap_unordered that exposes kwargs to the function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p
|
Pool
|
the multiprocessing.pool.Pool to use. |
required |
fn
|
Callable[..., Any]
|
the function to call, which accepts keyword arguments. |
required |
kwargs_list
|
list[dict[str, Any]]
|
list of kwargs dicts to pass to the function. |
required |
Returns:
| Type | Description |
|---|---|
IMapIterator
|
generator for outputs from the function in arbitrary order. |
Source code in rslearn/utils/mp.py
make_pool_and_star_imap_unordered ¶
make_pool_and_star_imap_unordered(workers: int, fn: Callable[..., Any], kwargs_list: list[dict[str, Any]]) -> Iterator[Iterable[Any]]
Context manager that creates a pool and yields an imap_unordered iterable.
When workers <= 0, runs sequentially in the current process with no pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workers
|
int
|
number of worker processes. 0 means no multiprocessing. |
required |
fn
|
Callable[..., Any]
|
the function to call, which accepts keyword arguments. |
required |
kwargs_list
|
list[dict[str, Any]]
|
list of kwargs dicts to pass to the function. |
required |
Yields:
| Type | Description |
|---|---|
Iterable[Any]
|
iterable of outputs from the function (arbitrary order). |