Parallelism API¶
The threads of every parallel method and the levels that run in parallel. Guide: Threads and Parallelism.
set_threads ¶
Set the number of threads of every parallel method, in this context.
The setting holds in the current Python thread (a contextvars
context), not in other threads. Without it, commol uses one thread per
core and every level in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The number of threads, at least 1. |
required |
levels
|
(all, outer)
|
Which levels run in parallel when a method nests them; |
"all"
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in commol/api/parallelism.py
threads ¶
Limit the threads of every parallel method within a block.
The previous setting comes back when the block ends, also on an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int | None
|
The number of threads, at least 1; |
None
|
levels
|
(all, outer)
|
Which levels run in parallel when a method nests them; |
"all"
|
Yields:
| Type | Description |
|---|---|
None
|
The block runs with the setting. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in commol/api/parallelism.py
get_threads ¶
The number of threads of the parallel methods in this context.
Returns:
| Type | Description |
|---|---|
int
|
The number set, or the number of cores when none is set. |
get_levels ¶
The levels that run in parallel in this context.
Returns:
| Type | Description |
|---|---|
{all, outer}
|
The levels set, or |