diff --git a/README.md b/README.md index 1289453..5e034cc 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ evaluate expressions, and stream from generators - all without blocking Erlang schedulers. **Parallelism options:** -- **Worker mode** (default, recommended) - Works with any Python version. With free-threaded Python (3.13t+), provides true parallelism automatically. +- **Worker mode** (default, recommended) - Works with every supported Python version. With free-threaded Python (3.13t+), provides true parallelism automatically. - **OWN_GIL sub-interpreters** (Python 3.14+) - Each interpreter has its own GIL, true parallelism. - **BEAM processes** - Fan out work across lightweight Erlang processes. @@ -38,7 +38,8 @@ Key features: ## Requirements - Erlang/OTP 28 or later (tested on OTP 28 and 29) -- Python 3.12+ (3.13+ for free-threading) +- CPython 3.12+ with matching development headers (`Python.h`); 3.13+ for free-threading +- rebar3 and CMake 3.18 or later - C compiler (gcc, clang) ## Building @@ -112,11 +113,8 @@ Register Erlang or Elixir functions that Python code can call back into: py:register_function(my_func, fun([X, Y]) -> X + Y end). %% Call from Python - native import syntax (recommended) -{ok, Result} = py:exec(<<" -from erlang import my_func -result = my_func(10, 20) -">>). -%% Result = 30 +ok = py:exec(<<"from erlang import my_func">>). +{ok, 30} = py:eval(<<"my_func(10, 20)">>). %% Or use attribute-style access {ok, 30} = py:eval(<<"erlang.my_func(10, 20)">>). @@ -137,10 +135,8 @@ py:unregister_function(my_func). end) # Call from Python - native import syntax -{:ok, 3628800} = :py.exec(""" -from erlang import factorial -result = factorial(10) -""") +:ok = :py.exec("from erlang import factorial") +{:ok, 3628800} = :py.eval("factorial(10)") # Or use attribute-style access {:ok, 3628800} = :py.eval("erlang.factorial(10)") @@ -632,7 +628,7 @@ Bulk data crosses through shared memory (`py_shm`, with the optional [iommap](https://hex.pm/packages/iommap) dependency). See [Isolated Contexts](docs/isolated.md). -**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). +**Worker mode is recommended** because it works with every supported 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). **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. diff --git a/docs/isolated.md b/docs/isolated.md index 009d517..1bb78b8 100644 --- a/docs/isolated.md +++ b/docs/isolated.md @@ -49,7 +49,7 @@ Options of `py_context:new/1` specific to this mode: | Option | Default | Meaning | |---|---|---| -| `python` | interpreter matching the embedded runtime (`py:python_executable/0`), or `isolated_python` app env | Executable to run | +| `python` | `isolated_python` application setting if set, otherwise the interpreter matching the embedded runtime (falling back to `python3` on `PATH`) | Executable for the child process | | `rlimits` | `#{}` | `#{as => Bytes, cpu => Seconds, nofile => N}`, applied with `setrlimit` before any user code | | `cgroup` | none | Path of a cgroup v2 directory the child joins (limits written by you: `memory.max`, `cpu.max`, `pids.max`) | | `env` | `#{}` | Extra environment variables for the child | diff --git a/docs/migration.md b/docs/migration.md index 5f6e1e6..13b601a 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -7,7 +7,7 @@ This guide covers breaking changes and migration steps when upgrading erlang_pyt ### Quick Checklist - [ ] Update `py:execution_mode/0` usage - now returns `worker | owngil` only -- [ ] Remove any `py:num_executors/0` calls (function removed) +- [ ] Remove calls to the former executor count function, `py:num_executors()` - [ ] Update code that checks for `free_threaded` or `multi_executor` modes - [ ] Review `context_mode` configuration (now `worker | owngil`) @@ -36,7 +36,7 @@ application:set_env(erlang_python, context_mode, owngil). ### Removed Functions -**`py:num_executors/0`** - Removed. Contexts now use per-context worker threads. +Each context now has its own worker thread. Remove calls to `py:num_executors()`. ```erlang diff --git a/docs/sessions.md b/docs/sessions.md index ee1d6f0..9fb27eb 100644 --- a/docs/sessions.md +++ b/docs/sessions.md @@ -112,9 +112,11 @@ ok = py_session:close(S). `orders` is imported fresh on the first call and kept for the next ones; another session has its own copy. `py_context:exec/eval` use the session's own `__main__`, and `py:call(S, ...)` works too. A callback can call back -into the same session. The modules are freed on `close/1`, when the -process that opened the session crashes, or if the session process is -killed. +into the same session. `py_session:close/1` closes the re-import session +without waiting for Python. If a call is still running, even after its +caller timed out, the shared context finishes it before freeing the +session's modules. Cleanup also runs if the owner crashes or the session +process is killed. The session runs on one of the template's contexts, shared with other sessions, so two things differ from a fork session: diff --git a/docs/shared-dict.md b/docs/shared-dict.md index e94abe7..16b704a 100644 --- a/docs/shared-dict.md +++ b/docs/shared-dict.md @@ -298,6 +298,6 @@ cache['computed'] = 42 ## See Also -- [State API](state.md) - Global shared state (different scope) +- [Shared state between workers](../README.md#shared-state-between-workers) - Access values by key across workers - [Channel](channel.md) - Message passing between Erlang and Python - [Getting Started](getting-started.md) - Basic usage guide diff --git a/docs/workers.md b/docs/workers.md index 74b83bf..bf3a85a 100644 --- a/docs/workers.md +++ b/docs/workers.md @@ -157,9 +157,9 @@ ok = py_context:start_loop(W). %% same context, fresh loop the loop is stopped. - Put workers under your own supervisor. `py_context` processes are `temporary` under `py_context_sup`; a restart is `py_context:new/1` again, - `start_loop`, and a new dup of the listen fd. Use `memory_limit` in - `py_context:new/1` to cap a worker, and `py_nif:context_memory_usage/1` to - watch it. + `start_loop`, and a new dup of the listen fd. For an `owngil` worker, + see [Per-context memory caps](memory.md#per-context-memory-caps) for how + to enable memory limits, set a cap in bytes and read current usage. ## Rules