Open
Conversation
Executes Python code on all workers in the pool. Useful for initializing shared state, importing modules, or defining functions across all workers.
e600013 to
355b75a
Compare
Add py:new_env/1,2 to create reusable Python environments with
initialization code. Environments can be named for global lookup
via persistent_term.
New API:
- py:new_env(Code) / py:new_env(Code, #{name => atom()})
- py:set_env(Name | Ref) - set current env for process
- py:get_env() / py:get_env(Name) - get current/named env
- py:list_envs() - list all named environments
- py:destroy_env(Ref) - remove from registry
When a named env is set, py:eval/exec and py_event_loop_pool:eval/exec
use it directly via NIF instead of routing through contexts.
Remove preload API from py_event_loop_pool in favor of named
environments which provide more flexibility.
355b75a to
4c9ff1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
py:new_env/1,2to create reusable Python environments with initialization codepy:set_env/1,py:get_env/0,1,py:list_envs/0,py:destroy_env/1py:eval/execandpy_event_loop_pool:eval/execto use named env when setExample usage:
{ok, _} = py:new_env(<<"import numpy as np">>, #{name => numpy_env}), ok = py:set_env(numpy_env), {ok, Result} = py:eval(<<"np.array([1,2,3])">>).