PythonCall.jl icon indicating copy to clipboard operation
PythonCall.jl copied to clipboard

Segmentation fault on jl.seval("using ...")

Open darnstrom opened this issue 5 months ago • 8 comments

Affects: JuliaCall

Describe the bug In the package pdaqp I am using juliacall to wrap the Julia package ParametricDAQP.jl I have not observed this myself, but we have had some problems with segmentation faults on ubuntu-latest runners when pdaqp is used in cvxpygen, and now other users have also started observing this.

Your system Since I am not able to reproduce the segmentation fault on my own system, an example of when the problem arises is given in this issue. Where some system information and a trace is given.

Additional context Is there some best practices here that I can use to avoid segmentation faults. I have based a lot of the wrapper on how PySR uses juliacall, so maybe @MilesCranmer have some insight? Here is the section of pdaqp where juliacall is setup: https://github.com/darnstrom/pdaqp/blob/bf511826beae525b794537dd7b413d6005e7a9ad/src/pdaqp/pdaqp.py#L1C1-L16C34 The segmentation fault seems to happen on line 15: jl.seval("using ParametricDAQP")

darnstrom avatar Jul 14 '25 08:07 darnstrom

Can you share your reproducer on https://github.com/JuliaLang/julia/issues/58171? The more people affected by it, the faster we can get support, so it's good if we can emphasise how widespread and disruptive it is.

Also see:

  • https://github.com/JuliaPy/PythonCall.jl/issues/586
  • https://github.com/JuliaPy/PythonCall.jl/pull/635#issuecomment-3042334536 (though this is sadly not an actual fix)

MilesCranmer avatar Jul 14 '25 10:07 MilesCranmer

Thanks for the links @MilesCranmer. I reported our segfault in the issue you linked. It is interesting that we have only observed it on ubuntu-latest so far, while you seem to have observed it mainly on mac.

Its sporadic nature makes it very frustrating to debug...

darnstrom avatar Jul 14 '25 11:07 darnstrom

Thanks!

I've also posted on the discourse in hopes of getting wider help: https://discourse.julialang.org/t/desperate-plea-for-segfault-assistance/130697.

It seems like this segfault is affecting a lot of people now so should be prioritized

MilesCranmer avatar Jul 14 '25 11:07 MilesCranmer

Can you confirm the Python and Julia versions involved?

mkitti avatar Jul 14 '25 13:07 mkitti

@mkitti The versions in the issue I linked are Julia 1.10.10 and Python 3.13.3, but I have had similar error with other versions (for example Julia 1.10.9 and Python 3.10)

darnstrom avatar Jul 14 '25 13:07 darnstrom

An MWE for the segfault on Python 3.13.1 + Julia 1.10.5 + macOS. No multithreading.

#!/usr/bin/env python3
"""
Minimal reproducible example for Python 3.13.1 + Julia DataFrames.jl segfault

To reproduce:
1. Install Python 3.13.1
2. Create a fresh virtual environment
3. Install juliacall: pip install juliacall==0.9.25
4. Run this script

Expected: DataFrames.jl loads successfully
Actual: Segmentation fault during precompilation
"""
import os
import sys

print(f"Python version: {sys.version}")
# Python version: 3.13.1 (main, Jan 14 2025, 23:31:50) [Clang 19.1.6 ]

# Set recommended environment variable
os.environ["JULIA_NUM_THREADS"] = "1"
os.environ["PYTHON_JULIACALL_HANDLE_SIGNALS"] = "yes" # with or without


from juliacall import Main as jl
jl.seval("using Pkg; Pkg.add(\"DataFrames\")")

# This line causes segfault during DataFrames precompilation on Python 3.13.1
print("\nLoading DataFrames.jl...")
jl.seval("using DataFrames")
# [1]    67441 segmentation fault  python minimal_dataframes_segfault.py

FuZhiyu avatar Jul 15 '25 03:07 FuZhiyu

It seems to be understood in the discourse thread. Just needs a patch and release now

MilesCranmer avatar Jul 15 '25 04:07 MilesCranmer

PythonCall 0.9.26 just released has the fix - can you try it and check it fixes this issue?

cjdoris avatar Jul 15 '25 18:07 cjdoris