Skip to content

Commit ac272a3

Browse files
Allow changing number of threads with env variable
1 parent 9cc65a9 commit ac272a3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

docs/reference/usage.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ pip install anywidget
2222

2323
It follows [SPEC 0](https://scientific-python.org/specs/spec-0000/) in terms of what Python versions are supported.
2424

25+
## Parallelism and threads
26+
27+
The underlying Rust library uses Rayon for parallelism. You can control the worker thread count via the environment variable `RAYON_NUM_THREADS`. If this variable is not set or is invalid, the Python bindings default to using a single thread (`1`).
28+
29+
```shell
30+
export RAYON_NUM_THREADS=4 # use 4 threads
31+
```
32+
2533
(community)=
2634

2735
## Community

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ use pyo3::prelude::*;
1111
/// Bindings for egglog rust library
1212
#[pymodule]
1313
fn bindings(m: &Bound<'_, PyModule>) -> PyResult<()> {
14+
// Configure Rayon thread pool from env var, defaulting to 1 if unset/invalid.
15+
let num_threads = std::env::var("RAYON_NUM_THREADS")
16+
.ok()
17+
.and_then(|s| s.parse::<usize>().ok())
18+
.unwrap_or(1);
1419
rayon::ThreadPoolBuilder::new()
15-
.num_threads(1)
20+
.num_threads(num_threads)
1621
.build_global()
1722
.unwrap();
1823

0 commit comments

Comments
 (0)