GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add import_ensure_initialized to import_module_level by youknowone · Pull Request #7076 · RustPython/RustPython

Conversation

@youknowone

@youknowone youknowone commented Feb 11, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions
@youknowone
Add import_ensure_initialized to import_module_level
39cd2f6
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

coderabbitai Bot commented Feb 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
📝 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

  • Fix test_import: import machinery, circular imports, and script shadowing #7034: Directly related as both PRs modify the same import synchronization logic in import_module_level to handle partially-initialized modules via __spec__._initializing.

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 docstrings
🧪 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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

Comment @coderabbitai help to get the list of available commands and usage tips.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone marked this pull request as ready for review February 11, 2026 00:33
@youknowone
youknowone merged commit 36ff461 into RustPython:main Feb 11, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone deleted the import branch February 11, 2026 01:57
youknowone added a commit to youknowone/RustPython that referenced this pull request Mar 22, 2026
@youknowone
Add import_ensure_initialized to import_module_level (RustPython#7076)
42c0d25
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
@youknowone
Add import_ensure_initialized to import_module_level (#7076)
1fa991d
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

1 participant

@youknowone
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.