frame: support importing under sub-interpreters - #340
Open
jinh-labs wants to merge 1 commit into
Open
Conversation
Python 3.12 won't load single-phase C extensions inside a sub-interpreter. Convert _frame to multi-phase init so it imports there, and declare it safe to run with a per-interpreter GIL. _frame keeps no shared global state — each compression/decompression context is allocated per call — so this is safe. No API change, and older Python versions are unaffected.
This was referenced Jul 27, 2026
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.
What
Python 3.12+ won't import single-phase C extensions inside a sub-interpreter.
This converts
_frameto multi-phase init so it imports there, and declares itsafe to run with a per-interpreter GIL.
Part of #345 - multi-phase init for the
_framemodule (see also #341_block, #342_stream, #343_version).Why it's safe
_framekeeps no shared global state: each compression/decompression context isallocated per call and freed with the object it's wrapped in, and there are no
custom module globals or static types. The bundled liblz4 is reentrant. So the
module is safe even in fully isolated interpreters.
Compatibility
No API change. The new declaration is guarded for Python 3.12+, so builds on
older Python are unaffected.
Scope
This covers the
framesubmodule only.block,stream, and_versionarestill single-phase, so
import lz4as a whole doesn't work under asub-interpreter yet — those are follow-ups. This PR makes the
_frameextensionitself compatible, which is the foundation for the rest.
Testing
tests/frame/passes (12,587 tests)._frameimports and round-trips inside an isolated, own-GILsub-interpreter (checked with both the
_xxsubinterpretersAPI and a C harnessthat enables the multi-interpreter check).
Refs: PEP 489, Isolating Extension Modules