You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
True parallelism without GIL contention using Python 3.12+ sub-interpreters:
317
+
True parallelism without GIL contention using Python 3.14+ OWN_GIL sub-interpreters:
317
318
318
319
```erlang
319
-
%% Execute multiple calls in parallel across sub-interpreters
320
+
%% Execute multiple calls in parallel across OWN_GIL sub-interpreters
321
+
%% Requires Python 3.14+
320
322
{ok, Results} =py:parallel([
321
323
{math, factorial, [100]},
322
324
{math, factorial, [200]},
@@ -326,6 +328,8 @@ True parallelism without GIL contention using Python 3.12+ sub-interpreters:
326
328
%% Each call runs in its own interpreter with its own GIL
327
329
```
328
330
331
+
For Python 3.12/3.13, use SHARED_GIL sub-interpreters (`mode => subinterp`) for namespace isolation, but note that parallelism is limited by the shared GIL.
332
+
329
333
## Parallel Processing with BEAM Processes
330
334
331
335
Leverage Erlang's lightweight processes for massive parallelism:
@@ -595,19 +599,47 @@ ok = py:clear_traces().
595
599
596
600
## Execution Modes
597
601
598
-
The library auto-detects the best execution mode:
602
+
### Context Modes
599
603
600
-
| Mode | Python Version | Parallelism |
604
+
When creating Python contexts, you can choose the execution mode:
605
+
606
+
| Mode | Python Version | Description |
601
607
|------|----------------|-------------|
602
-
| Free-threaded | 3.13+ (nogil) | True parallel, no GIL |
603
-
| Sub-interpreter | 3.12+ | Per-interpreter GIL |
604
-
| Multi-executor | Any | GIL contention |
608
+
|`worker`| Any | Main interpreter, shared namespace (default, recommended) |
%% With free-threaded Python (3.13t+), provides true parallelism automatically
615
+
{ok, Ctx} =py_context:new(#{}).
616
+
617
+
%% Explicit subinterpreter with shared GIL (Python 3.12+)
618
+
%% Provides namespace isolation but no parallelism
619
+
{ok, Ctx} =py_context:new(#{mode=>subinterp}).
620
+
621
+
%% OWN_GIL mode for true parallelism (Python 3.14+ required)
622
+
%% Each context runs in its own pthread with independent GIL
623
+
{ok, Ctx} =py_context:new(#{mode=>owngil}).
624
+
```
625
+
626
+
**Worker mode is recommended** because it works with any Python version and automatically benefits from free-threaded Python (3.13t+) when available.
627
+
628
+
**Why OWN_GIL requires Python 3.14+**: Some C extensions (e.g., `_decimal`, `numpy`) have global state bugs in sub-interpreters on Python 3.12/3.13. These are fixed in Python 3.14. SHARED_GIL mode works on 3.12+ but with caveats for C extensions with global state.
0 commit comments