GeezerVison is showing github.com — Add import_ensure_initialized to import_module_level by youknowone · Pull Request #7076 · RustPython/RustPython
Conversation
youknowone
commented
Feb 11, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Wait for module initialization to complete when a module is already in sys.modules but still being initialized by another thread. Check spec._initializing and call
_lock_unlock_module to block until the import finishes.
Summary by CodeRabbit
- Bug Fixes
- Improved module import synchronization to properly handle concurrent and nested imports, ensuring modules are fully initialized before use and preventing edge case issues.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Wait for module initialization to complete when a module is
already in sys.modules but still being initialized by another
thread. Check __spec__._initializing and call
_lock_unlock_module to block until the import finishes.
coderabbitai
Bot
commented
Feb 11, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
A new private helper function import_ensure_initialized is added to handle synchronization of module imports. It checks whether a module's __spec__._initializing flag is set and calls importlib's _lock_unlock_module to wait for initialization completion. The helper is integrated into import_module_level to ensure pre-existing modules are fully initialized before returning.
Changes
| Cohort / File(s) |
Summary |
Module Import Synchronization crates/vm/src/import.rs |
Added private import_ensure_initialized() helper function that waits for partially-initialized modules to complete their initialization by checking __spec__._initializing and calling importlib's locking mechanism. Integrated into import_module_level to synchronize module lookup and return. |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Poem
🐰 A module waits, caught mid-creation,
But now we ensure initialization—
With locks and flags in harmony,
Imports flow safe and clean, you see! ✨
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title accurately and concisely summarizes the main change: adding the import_ensure_initialized function to import_module_level. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
No actionable comments were generated in the recent review. 🎉
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
youknowone
added a commit
to youknowone/RustPython
that referenced
this pull request
Mar 22, 2026
Wait for module initialization to complete when a module is
already in sys.modules but still being initialized by another
thread. Check __spec__._initializing and call
_lock_unlock_module to block until the import finishes.
youknowone
added a commit
that referenced
this pull request
Sep 16, 2026
Wait for module initialization to complete when a module is
already in sys.modules but still being initialized by another
thread. Check __spec__._initializing and call
_lock_unlock_module to block until the import finishes.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.