Conversation
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.
Motivation
@pyregion/@pyregionbreak) that amortize attach/detach transitions without exposing GIL details.Description
Regionthat implements per-OS-thread persistent PythonCall-ownedPyThreadState+ cooperative semaphore, and per-task dynamicTaskStatewith stickiness and token-based nested enter/exit semantics; exported macros@pyregionand@pyregionbreakuse this machinery. (src/Region/Region.jl,src/API/macros.jl,src/API/exports.jl)Py_FinalizeEx(). (src/C/context.jl,src/Region/Region.jl,src/PythonCall.jl)PyGILState_*usage internally for region semantics and exposed macros; provided a compatibility layer for the existingPythonCall.GILAPI by routing it through the new region enter/exit functions. (src/GIL/GIL.jl,src/C/pointers.jl)@pyregion/@pyregionbreakthroughout the core C-API call sites to ensure correct attach/detach behavior while keeping regions tight; updated@pylowering so generated code has one outer@pyregionand each@jlsplice becomes a@pyregionbreak. (bulk edits undersrc/Core/*,src/PyMacro/PyMacro.jl,src/JlWrap/*,src/GC/GC.jl,src/Core/builtins.jl)PythonCall.GC.gc()can be used to drain the queue inside a region. (src/GC/GC.jl,test/GC.jl)PyThreadState_GetUnchecked/_PyThreadState_UncheckedGet) andPyThreadState_Newusage for persistent per-thread states. (src/C/pointers.jl,src/C/C.jl)test/Region.jl)1.12to rely onOncePerThread/OncePerTaskprimitives and updated julia/juliapkg metadata where appropriate.Testing
JULIA_NUM_THREADS=4 julia --project -e 'using Pkg; Pkg.test()'— all tests passed (4,095 tests passed).JULIA_NUM_THREADS=4 julia --project -e 'using Pkg; Pkg.test(coverage=true)'— suite passed (4,095 tests passed); uncovered lines are limited to defensive rollback/impossible-token branches and the Python-originated root-break path that requires JuliaCall-specific scenarios.Threads.@spawnto verify detached initialization and cross-thread Python calls — succeeded (simple runtime checks demonstratedPyThreadState_GetUnchecked()is NULL outside regions and that@pyregionamortizes transitions).uv run pytest -s --nbval ./pytest) but they failed to run in this environment due to an external constraint: the environment's Python 3.14 OpenSSL/juliapkg interaction restricts Julia to ≤1.11 and therefore conflicts with the new Julia ≥1.12 requirement; the Python tests are otherwise intended to run in a matching environment and were not failing due to region logic.docs/make.jl; Documenter ran but could not infer repository remote source links because this checkout lacks a valid origin remote (non-test blocking).If you want, I can (1) open follow-ups to address remaining minor uncovered branches and defensive assertions, (2) add CI matrix notes to run the Python tests under a Python/Julia combination that satisfies OpenSSL/juliapkg constraints, or (3) narrow/expand any
@pyregionplacements based on preferred granularity.Codex Task