Skip to content

Commit

Permalink
rearrange slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Dec 13, 2024
1 parent 6f2eb15 commit aaaf0a9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions guide/src/parallelism.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,16 @@ in parallel. It is also possible to spawn threads in Rust that acquire the GIL
and operate on Python objects. However, care must be taken to avoid writing code
that deadlocks with the GIL in these cases.

In the example below, we share a `Vec` of User ID objects defined using the
`pyclass` macro and spawn threads to process the collection of data into a `Vec`
of booleans based on a predicate using a rayon parallel iterator:

* Note: This example is meant to illustrate how to drop and re-acquire the GIL
to avoid creating deadlocks. Unless the spawned threads subsequently
release the GIL or you are using the free-threaded build of CPython, you
will not see any speedups due to multi-threaded parallelism using `rayon`
to parallelize code that acquires the GIL.
to parallelize code that acquires and holds the GIL for the entire
execution of the spawned thread.

In the example below, we share a `Vec` of User ID objects defined using the
`pyclass` macro and spawn threads to process the collection of data into a `Vec`
of booleans based on a predicate using a rayon parallel iterator:

```rust,no_run
use pyo3::prelude::*;
Expand Down

0 comments on commit aaaf0a9

Please sign in to comment.