Add automatic env reuse for py_event_loop:run#33
Merged
Conversation
bff3aa1 to
2f73bc2
Compare
When a process has a local Python environment (from py:context/py:exec), py_event_loop functions now automatically pass that env to the NIF. This allows functions defined via py:exec to be called directly without manual env parameter passing. Key implementation detail: env resources are stored in a PID->env mapping (not serialized through the task queue) to avoid memory safety issues with resource serialization across NIF environments. Changes: - Add pid_env_mapping_t struct for storing PID->env mappings - Add register_pid_env/lookup_pid_env helper functions - Modify nif_submit_task_with_env to register env by PID - Modify process_ready_tasks to look up env by caller PID - Move py_env_resource_t definition to py_nif.h for shared access - Update py_event_loop:create_task to auto-detect and pass process env - Update py_event_loop:spawn_task to use caller's env - Add tests for env reuse with sync, async, and spawn_task functions
2f73bc2 to
90936e1
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:exec(Ctx, Code)can now be called viapy_event_loop:runwithout manual env passingExample: