# Juliacall / PythonCall array conversion crash (now with MWE)

**URL:** <https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318>\
**Category:** General Usage\
**Tags:** array, python, intero\
**Created:** [August 3, 2025, 2:33pm UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318 "2025-08-03T14:33:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [August 3, 2025, 2:33pm UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318/1 "2025-08-03T14:33:57Z")

</div>

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:

```julia-auto
# 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?

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [August 3, 2025, 4:33pm UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318/2 "2025-08-03T16:33:00Z")

</div>

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](https://discourse.julialang.org/t/plea-for-segfault-assistance-in-pythoncall-jl/130697) and [this post](https://discourse.julialang.org/t/plea-for-segfault-assistance-in-pythoncall-jl/130697/27) in particular, perhaps you could check if downgrading to Python 3.11 or earlier helps?

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [August 4, 2025, 2:57am UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318/3 "2025-08-04T02:57:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [August 4, 2025, 4:51am UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318/4 "2025-08-04T04:51:48Z")

</div>

The problem seems to disappear after I upgraded from juliacall 0.9.25 (May 2025) to the latest 0.9.26 (Jul 2025), with either Python 3.10 or 3.13. At least no crashes have been seen so far.

---

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [August 4, 2025, 3:40pm UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318/5 "2025-08-04T15:40:50Z")

</div>

Yeah this segfault was fixed on juliacall 0.9.26 [Switch to heap types using PyType\_FromSpec by cjdoris · Pull Request #643 · JuliaPy/PythonCall.jl · GitHub](https://github.com/JuliaPy/PythonCall.jl/pull/643)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [August 4, 2025, 4:38pm UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318/6 "2025-08-04T16:38:04Z")

</div>

Interesting that this segfault was observed on Python 3.10 when your thread discussing the issue found the missing fields were added in 3.12 and 3.13. Were there actually more missing fields, maybe only on some platforms?
