block: support importing under sub-interpreters - #341
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 _block to multi-phase init so it imports there, and declare it safe to run with a per-interpreter GIL. LZ4BlockError moves from a global into per-module state, so every interpreter gets its own. No API change, and older Python versions are unaffected.
jinh-labs
force-pushed
the
subinterp-compat-block
branch
from
July 7, 2026 09:29
240b375 to
eaf9882
Compare
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
_blockto 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
_blockmodule (see also #340_frame, #342_stream, #343_version).Why it's safe
LZ4BlockErrormoves from a module global into per-module state, so eachinterpreter gets its own copy. There is no other shared mutable state, and 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. (Uses
PyModule_AddObjectrather thanPyModule_AddObjectRefto keep the 3.9 minimum.)Testing
tests/blockpasses (7,217 tests)._blockimports and round-trips in isolated, own-GILsub-interpreters, and that
LZ4BlockErroris a distinct object perinterpreter.
Refs: PEP 489, Isolating Extension Modules