|
62 | 62 | %% Exported for py_reactor_context |
63 | 63 | -export([extend_erlang_module_in_context/1]). |
64 | 64 |
|
65 | | --type context_mode() :: auto | subinterp | worker | owngil. |
| 65 | +-type context_mode() :: worker | subinterp | owngil. |
66 | 66 | -type context() :: pid(). |
67 | 67 |
|
68 | 68 | -export_type([context_mode/0, context/0]). |
|
82 | 82 | %% @doc Start a new py_context process. |
83 | 83 | %% |
84 | 84 | %% The process creates a Python context based on the mode: |
85 | | -%% - `auto' - Detect best mode (subinterp on Python 3.12+, worker otherwise) |
86 | | -%% - `subinterp' - Create a sub-interpreter with shared GIL (uses pool) |
87 | 85 | %% - `worker' - Create a thread-state worker (main interpreter namespace) |
88 | | -%% - `owngil' - Create a sub-interpreter with its own GIL (true parallelism) |
| 86 | +%% - `subinterp' - Create a sub-interpreter with shared GIL (Python 3.12+) |
| 87 | +%% - `owngil' - Create a sub-interpreter with its own GIL (Python 3.14+) |
89 | 88 | %% |
90 | 89 | %% The `owngil' mode creates a dedicated pthread for each context, allowing |
91 | | -%% true parallel Python execution. This is useful for CPU-bound workloads. |
92 | | -%% Requires Python 3.12+. |
| 90 | +%% true parallel Python execution. Requires Python 3.14+. |
93 | 91 | %% |
94 | 92 | %% @param Id Unique identifier for this context |
95 | 93 | %% @param Mode Context mode |
@@ -128,13 +126,13 @@ stop(Ctx) when is_pid(Ctx) -> |
128 | 126 | %% @doc Create a new context with options map. |
129 | 127 | %% |
130 | 128 | %% Options: |
131 | | -%% - `mode' - Context mode (auto | subinterp | worker | owngil), default: auto |
| 129 | +%% - `mode' - Context mode (worker | subinterp | owngil), default: worker |
132 | 130 | %% |
133 | 131 | %% @param Opts Options map |
134 | 132 | %% @returns {ok, Pid} | {error, Reason} |
135 | 133 | -spec new(map()) -> {ok, context()} | {error, term()}. |
136 | 134 | new(Opts) when is_map(Opts) -> |
137 | | - Mode = maps:get(mode, Opts, auto), |
| 135 | + Mode = maps:get(mode, Opts, worker), |
138 | 136 | Id = erlang:unique_integer([positive]), |
139 | 137 | start_link(Id, Mode). |
140 | 138 |
|
@@ -521,19 +519,10 @@ apply_registered_paths(Ref) -> |
521 | 519 | end. |
522 | 520 |
|
523 | 521 | %% @private |
524 | | -%% Auto mode uses subinterpreters only on Python 3.14+ where C extension |
525 | | -%% global state bugs (e.g., _decimal) are fixed. On Python 3.12/3.13, |
526 | | -%% use worker mode to avoid crashes from C extensions like _decimal. |
527 | | -%% Users can still explicitly use subinterp mode if needed. |
528 | | -create_context(auto) -> |
529 | | - case py_nif:owngil_supported() of |
530 | | - true -> create_context(subinterp); |
531 | | - false -> create_context(worker) |
532 | | - end; |
533 | | -create_context(subinterp) -> |
534 | | - py_nif:context_create(subinterp); |
535 | 522 | create_context(worker) -> |
536 | 523 | py_nif:context_create(worker); |
| 524 | +create_context(subinterp) -> |
| 525 | + py_nif:context_create(subinterp); |
537 | 526 | create_context(owngil) -> |
538 | 527 | %% OWN_GIL mode requires Python 3.14+ due to C extension bugs in earlier versions |
539 | 528 | case py_nif:owngil_supported() of |
|
0 commit comments