Multithreading with PythonCall and PythonPlot leads to a EXCEPTION_ACCESS_VIOLATION
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 src\Pythoncall_testing.jl 開始,使用 Julia 1.12.5、PythonCall 0.9.31、PythonPlot 1.0.6、Windows 和 10 個執行緒重現當機。結合 PythonCall.GIL.@unlock,閱讀 PythonPlot 的 init 和 pyGui.jl 第 198 行附近的堆疊追蹤。理解此互動,且回報的存取違規不再出現在最小範例中,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Affects: PythonCall
Bug description
Having both PythonCall and PythonPlot imported leads to a EXCEPTION_ACCESS_VIOLATION when used with multithreading with an unlocked GIL.
MWE
File: src\Pythoncall_testing.jl
import PythonCall
import PythonPlot
PythonCall.GIL.@unlock Threads.@threads for i in 1:5
println("Hello world")
end
Commands
Command line:
C:\Users\kuhrmann\CODE\pythoncall_testing>julia -t 10
] activate .
include("src\\Pythoncall_testing.jl")
Output
C:\Users\kuhrmann\CODE\pythoncall_testing>julia -t 10
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.12.5 (2026-02-09)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org release
|__/ |
(@v1.12) pkg> activate .
Activating project at `C:\Users\kuhrmann\CODE\pythoncall_testing`
julia> include("src\\Pythoncall_testing.jl")
Hello world
Hello world
Hello world
Hello world
Hello world
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffbe8a26c09 -- PyType_GenericAlloc at C:\Users\kuhrmann\CODE\pythoncall_testing\.CondaPkg\.pixi\envs\default\python314.dll (unknown line)
in expression starting at C:\Users\kuhrmann\CODE\pythoncall_testing\src\Pythoncall_testing.jl:4
PyType_GenericAlloc at C:\Users\kuhrmann\CODE\pythoncall_testing\.CondaPkg\.pixi\envs\default\python314.dll (unknown line)
PyUnicode_DecodeUTF8Stateful at C:\Users\kuhrmann\CODE\pythoncall_testing\.CondaPkg\.pixi\envs\default\python314.dll (unknown line)
PyUnicode_DecodeUTF8Stateful at C:\Users\kuhrmann\CODE\pythoncall_testing\.CondaPkg\.pixi\envs\default\python314.dll (unknown line)
PyUnicode_DecodeUTF8 at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\C\pointers.jl:300 [inlined]
pystr_fromUTF8 at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\builtins.jl:554
pystr_fromUTF8 at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\builtins.jl:555 [inlined]
pystr at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\builtins.jl:563 [inlined]
Py at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\Py.jl:125 [inlined]
macro expansion at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\Py.jl:117 [inlined]
pygetattr at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\builtins.jl:58
getproperty at C:\Users\kuhrmann\.julia\packages\PythonCall\83z4q\src\Core\Py.jl:275 [inlined]
#Tk_eventloop##0 at C:\Users\kuhrmann\.julia\packages\PythonPlot\oS8x4\src\pygui.jl:198
#634 at .\asyncevent.jl:361
unknown function (ip: 000001ead8510a6b) at (unknown file)
jl_apply at C:/workdir/src\julia.h:2391 [inlined]
start_task at C:/workdir/src\task.c:1252
Allocations: 3660481 (Pool: 3660333; Big: 148); GC: 5
C:\Users\kuhrmann\CODE\pythoncall_testing>
System info
Your system
Please provide detailed information about your system:
- The operating system: Win 11
- The version of Julia, Python, PythonCall, JuliaCall and any other affected packages
- If an issue with PythonCall, the output of
Base.versioninfo(),Pkg.status()andCondaPkg.status().
versioninfo()
Julia Version 1.12.5
Commit 5fe89b8ddc (2026-02-09 16:05 UTC)
Build Info:
Official https://julialang.org release
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 20 × 13th Gen Intel(R) Core(TM) i7-1370P
WORD_SIZE: 64
LLVM: libLLVM-18.1.7 (ORCJIT, alderlake)
GC: Built with stock GC
Threads: 10 default, 1 interactive, 10 GC (on 20 virtual cores)
Pkg.status()
Project Pythoncall_testing v0.1.0
Status `C:\Users\kuhrmann\CODE\pythoncall_testing\Project.toml`
[6099a3de] PythonCall v0.9.31
[274fc56d] PythonPlot v1.0.6
CondaPkg.status()
CondaPkg Status C:\Users\kuhrmann\CODE\pythoncall_testing\CondaPkg.toml (empty)
Environment
C:\Users\kuhrmann\CODE\pythoncall_testing\.CondaPkg\.pixi\envs\default
Additional context
I dont want to use multithreading to plot on many threads, I just have a julia project in which I do multithreaded computation involving python, and the results of which I would like to plot with matplotlib.
From the stacktrace, it seems as though PythonPlot.__init__() gets called by each thread, which in turn calls python.
I belive this leads to a crash as the GIL is unlocked (PythonCall.GIL@unlock) but was not locked before the PythonPlot.__init__().
This is quite frustrating, as I need both PythonCall and PythonPlot and I would like to not have to separate them at the project level.
Is there some way to avoid this? Perhaps I can somehow make sure the the PythonPlot.__init__() calls are wrapped with PythonCall.GIL.@lock?
Let me know if something is unclear!
Thanks for the convenient package otherwise!
- 主要語言
- Julia
- 星號
- 1.1k
- 分支
- 89
- 平均合併
- 2 天 15 小時
- 30 天內合併 PR
- 7
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
JuliaPy/PythonCall.jl 的其他 Issue
-
難度 3/5 1-2 天 新手友好度 55/100
JuliaPy/PythonCall.jl#828 · 7 則留言 ·
維護者通常 1 天內回覆
-
bug
難度 4/5 3-5 天 新手友好度 48/100
JuliaPy/PythonCall.jl#809 · 2 則留言 ·
維護者通常 1 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 35/100
JuliaPy/PythonCall.jl#805 · 4 則留言 ·
維護者通常 1 天內回覆
-
enhancement
難度 3/5 1-2 天 新手友好度 68/100
JuliaPy/PythonCall.jl#796 ·
維護者通常 1 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 25/100
JuliaPy/PythonCall.jl#790 ·
維護者通常 1 天內回覆
查看 JuliaPy/PythonCall.jl 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 78/100
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 76/100
JuliaPhysics/BeamletOptics.jl#127 ·
維護者通常 1 天內回覆
-
Chains resumed from `initial_state` take `num_warmup + 1` warm-up steps可能已有人在做 @thevolatilebit 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 80/100
TuringLang/AbstractMCMC.jl#220 ·
-
found-by-agent
難度 2/5 1-3 小時 新手友好度 68/100
exanauts/SparseDirectSolver.jl#92 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆