Conversation
Adds explicit import caching for Python modules and functions:
API:
- py:import/1 - Import and cache a module
- py:import/2 - Import module and cache a specific function
- py:flush_imports/0 - Clear all import caches
- py:import_stats/0 - Get cache entry count
- py:import_list/0 - List cached imports as #{Module => [Funcs]}
Key behaviors:
- __main__ is never cached (returns error)
- Caching is per-process namespace (via PID affinity)
- All Python execution commands benefit from the cache
Tests:
- py_import_SUITE: 12 tests for basic import functionality
- py_import_owngil_SUITE: 9 tests for OWN_GIL mode (Python 3.12+)
- Multi-process and concurrent stress tests included
When using py_context:exec to define a function and then py_context:call with '__main__' as the module, the function was not found because '__main__' was looked up via PyImport_ImportModule (real Python module) instead of ctx->globals where exec stores defined functions. Add special handling to nif_context_call and owngil_execute_call to check ctx->globals first when module is '__main__', matching the existing behavior in nif_context_call_with_env.
string.ascii_lowercase is a string constant, not a callable function. The test was failing for contexts that included the string module because calling it raised TypeError. Use string.capwords instead.
- new/1: Create context with options map (mode => auto|subinterp|worker|owngil) - destroy/1: Alias for stop/1 for API consistency - call/4: Wrapper for call/5 with empty kwargs - eval/2: Wrapper for eval/3 with empty locals
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:import/1- Import and cache a modulepy:import/2- Import module and cache a specific functionpy:flush_imports/0- Clear all import cachespy:import_stats/0- Get cache entry countpy:import_list/0- List cached imports as#{Module => [Funcs]}Caching is per-process (via PID affinity) and
__main__is never cached.