Skip to content

Add process-bound Python environments#27

Open
benoitc wants to merge 3 commits intomainfrom
feature/process-bound-envs
Open

Add process-bound Python environments#27
benoitc wants to merge 3 commits intomainfrom
feature/process-bound-envs

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Mar 13, 2026

Summary

  • Each Erlang process gets its own Python globals/locals dict
  • Stored as NIF resource in process dictionary, auto-freed on exit
  • Worker mode only; subinterpreters keep full isolation

Changes

  • py_env_resource_t struct and create_local_env NIF
  • _with_env variants of context NIFs
  • py:get_local_env/0 using process dictionary
  • 4 new tests for isolation, main access, state persistence, cleanup

Each Erlang process gets its own Python globals/locals dict stored as a
NIF resource in the process dictionary. When the process exits, the
resource destructor frees the Python dicts.

Works in both worker and subinterpreter modes.

- Add py_env_resource_t and create_local_env NIF
- Add _with_env variants of context_exec/eval/call
- Add get_local_env/0 to py.erl using process dictionary
- Update py_context to pass EnvRef to NIFs
- Add tests for isolation, __main__ access, persistence, cleanup
@benoitc benoitc force-pushed the feature/process-bound-envs branch from 01e578c to 4ed57f8 Compare March 13, 2026 11:17
benoitc added 2 commits March 13, 2026 13:17
Subinterpreters have separate memory allocators. Env dicts must
be created inside the target interpreter to avoid free() errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant