Skip to content

Commit 7bdeaff

Browse files
committed
Pyodide: force only one thread
1 parent 3fbc10d commit 7bdeaff

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,5 +703,21 @@ fn rustworkx(py: Python<'_>, m: &Bound<PyModule>) -> PyResult<()> {
703703
m.add_class::<iterators::BiconnectedComponents>()?;
704704
m.add_class::<ColoringStrategy>()?;
705705
m.add_wrapped(wrap_pymodule!(generators::generators))?;
706+
#[cfg(target_os = "emscripten")]
707+
setup_rayon_for_pyodide();
706708
Ok(())
707709
}
710+
711+
#[cfg(target_os = "emscripten")]
712+
static PYODIDE_INIT: std::sync::Once = std::sync::Once::new();
713+
714+
#[cfg(target_os = "emscripten")]
715+
pub fn setup_rayon_for_pyodide() {
716+
PYODIDE_INIT.call_once(|| {
717+
rayon::ThreadPoolBuilder::new()
718+
.num_threads(1)
719+
.use_current_thread()
720+
.build_global()
721+
.expect("failing setting up threads for pyodide");
722+
});
723+
}

0 commit comments

Comments
 (0)