Juliacall / PythonCall array conversion crash (now with MWE)

Here’s the Python code which extracts a tuple of two Julia arrays from the juliacall interface and converts them to numpy arrays. The code is an infinite loop, but crashes sporadically after a few million iterations with segfault:

# juliacall_problem1.py

from juliacall import Main as jl
import numpy as np
counter = 0
while True:
    counter += 1
    try:
        a, b = jl.seval("(fill(0f0, 3, 8, 8), fill(true, 3, 8, 8))")
        c, d = np.array(a), np.array(b)
    except:
        print(f"Failed while {type(a) = }, {type(b) = }")
        break

print(f"Failed after {counter} iterations")

Here’s the result when I run the above script:

# python juliacall_problem1.py
/home/username/scratch/juliacall_problem1.py:8: DeprecationWarning: __array__ implementation doesn't accept a copy keyword, so passing copy=False failed. __array__ must implement 'dtype' and 'copy' keyword arguments. To learn more, see the migration guide https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword
  c, d = np.array(a), np.array(b)
Failed while type(a) = <class 'juliacall.ArrayValue'>, type(b) = <class 'juliacall.ArrayValue'>
Failed after 2994923 iterations
Segmentation fault         (core dumped) python juliacall_problem1.py

Versions: Linux x86_64, Python 3.13.3, julicall 0.9.25, Julia 1.11.5.

Maybe I should file an issue on GitHub?

1 Like

To add another data point: I get no issues (within 25 000 000 iterations) on Windows 11, Python 3.10.14, juliacall 0.9.26, Julia 1.11.6.

Considering this thread and this post in particular, perhaps you could check if downgrading to Python 3.11 or earlier helps?

1 Like

I tried Python 3.10.18 with juliacall 0.9.25, julia 1.11.6. The segfault also happened, every few hundred thousand iterations.