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
@@ -328,7 +324,7 @@ True parallelism without GIL contention using Python 3.14+ OWN_GIL sub-interpret
328
324
%% Each call runs in its own interpreter with its own GIL
329
325
```
330
326
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.
327
+
For Python 3.12/3.13 the public modes are `worker` (default) and `owngil` (Python 3.14+ only). Earlier versions run all contexts under the shared main interpreter via dedicated worker threads — namespace isolation between contexts is local-dict based, not via subinterpreters.
|`worker`| Any | Dedicated pthread per context, main interpreter namespace (default) |
605
+
|`owngil`| 3.14+ | Dedicated pthread + subinterpreter with its own GIL, true parallelism |
611
606
612
607
```erlang
613
608
%% Default: worker mode (recommended)
614
609
%% With free-threaded Python (3.13t+), provides true parallelism automatically
615
610
{ok, Ctx} =py_context:new(#{}).
616
611
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
612
%% OWN_GIL mode for true parallelism (Python 3.14+ required)
622
613
%% Each context runs in its own pthread with independent GIL
623
614
{ok, Ctx} =py_context:new(#{mode=>owngil}).
624
615
```
625
616
626
-
**Worker mode is recommended** because it works with any Python version and automatically benefits from free-threaded Python (3.13t+) when available.
617
+
**Worker mode is recommended** because it works with any Python version and automatically benefits from free-threaded Python (3.13t+) when available. Each context owns a dedicated pthread, providing stable thread affinity for libraries with thread-local state (numpy, torch, tensorflow).
627
618
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.
619
+
**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.
629
620
630
621
### Runtime Detection
631
622
632
-
Check the current execution mode:
623
+
Check the current execution mode (mirrors the `context_mode` application env):
0 commit comments