Skip to content

Segfault when calling python function repeatedly #626

Open
@jco255

Description

@jco255

my first issue go easy

Affects: PythonCall

Desribe:
I'm seeing segfaults after running for a while. I've tried to create a MWE, it usually segfaults first go, but sometimes I have to re-run the for-loop a few times. It feels like a gc race condition like i've seen in the other issues, but I have no real proof other than the more stuff i have going on, the faster it segfaults

using PythonCall

f1 = @pyexec """ 
def pyfunc(params):
    return 0
""" => pyfunc

params = Dict{String,Float64}(
    "A" => 1,
    "B" => 2,
    "C" => 3,
    )

for i in 1:10_000_000
    f1(params)
end
[965155] signal 11 (1): Segmentation fault                                                                                                                                                     
in expression starting at /home/olssoj2/git/julia_local/scratch_hy_mwe.jl:18                                                                                                                   
unknown function (ip: 0x7f30d83b03ae)                                                                                                                                                          
unknown function (ip: 0x7f30d82b1187)                                                                                                                                                          
Py_DecRef at /home/olssoj2/.julia/packages/PythonCall/L4cjh/src/C/pointers.jl:303 [inlined]                                                                                                    
pydel! at /home/olssoj2/.julia/packages/PythonCall/L4cjh/src/Core/Py.jl:114                                                                                                                    
#pycall#21 at /home/olssoj2/.julia/packages/PythonCall/L4cjh/src/Core/builtins.jl:244                                                                                                          
jl_apply at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
do_apply at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/builtins.c:831
#_#11 at /home/olssoj2/.julia/packages/PythonCall/L4cjh/src/Core/Py.jl:357
jl_apply at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
do_apply at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/builtins.c:831
Py at /home/olssoj2/.julia/packages/PythonCall/L4cjh/src/Core/Py.jl:357
top-level scope at /home/olssoj2/git/julia_local/scratch_hy_mwe.jl:19
jl_toplevel_eval_flex at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/toplevel.c:934
jl_toplevel_eval_flex at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/toplevel.c:886
ijl_toplevel_eval_in at /cache/build/tester-amdci5-12/julialang/julia-release-1-dot-11/src/toplevel.c:994
eval at ./boot.jl:430 [inlined]

Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 160 × Intel(R) Xeon(R) Platinum 8380 CPU @ 2.30GHz
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, icelake-server)
Threads: 1 default, 0 interactive, 1 GC (on 160 virtual cores)
Environment:
JULIA_NUM_THREADS =
JULIA_VSCODE_REPL = 1
JULIA_EDITOR = code
LD_LIBRARY_PATH = /opt/rh/gcc-toolset-14/root/usr/lib64:/opt/rh/gcc-toolset-14/root/usr/lib

(@v1.11) pkg> status PythonCall
Status ~/.julia/environments/v1.11/Project.toml
[6099a3de] PythonCall v0.9.25

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions