# Simple Python Program with Juliacall Segfaults

**URL:** <https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517>\
**Category:** General Usage\
**Tags:** interoperability, python, io\
**Created:** [October 29, 2025, 3:17pm UTC](https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517 "2025-10-29T15:17:20Z")\
**Posts on this page:** 5\
**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:** [October 29, 2025, 3:17pm UTC](https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517/1 "2025-10-29T15:17:20Z")

</div>

This simple Python program calling a Julia function crashes sporadically with segfault.

```python
# juliacall_compute_square.py
from juliacall import Main as jl
print(f"julia version : {jl.VERSION}")
numstring = input("Enter a number\n")
num = jl.parse(jl.Int, numstring)
print(num**2)

```

I tried running it 10 times in Linux Bash shell:

```bash
for i in {1..10}; do
    echo 50 | python juliacall_compute_square.py
done

```

I see 4 segfaults out of the 10 calls. I have Python 3.13.3, juliacall 0.9.28, Julia 1.12.1 with `versioninfo()` printout below:

```julia-auto
Commit ba1e628ee49 (2025-10-17 13:02 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 22 × Intel(R) Core(TM) Ultra 9 185H
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, alderlake)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 22 virtual cores)

```

---

<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:** [October 30, 2025, 10:45pm UTC](https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517/2 "2025-10-30T22:45:17Z")

</div>

Setting the environment variable `PYTHON_JULIACALL_THREADS=1` seems to help.

---

<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:** [October 31, 2025, 7:43pm UTC](https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517/3 "2025-10-31T19:43:20Z")

</div>

I seem to recall that newer versions of Python used to give difficulties for PythonCall.jl (though I also think it got fixed in the end). On Python 3.8.3 I get no issues, despite indeed being warned about potential multithreading issues.

```julia-auto
UserWarning: Julia was started with multiple threads but multithreading support is experimental in JuliaCall. It is recommended to restart Python with the environment variable PYTHON_JULIACALL_HANDLE_SIGNALS=yes set, otherwise you may experience segfaults or other crashes. Note however that this interferes with Python's own signal handling, so for example Ctrl-C will not raise KeyboardInterrupt. See https://juliapy.github.io/PythonCall.jl/stable/faq/#Is-PythonCall/JuliaCall-thread-safe? for further information. You can suppress this warning by setting PYTHON_JULIACALL_HANDLE_SIGNALS=no.

```

So perhaps downgrading to an older Python version is an option?

> **Version**
>
> - Python 3.8.3
> - juliacall 0.9.26
> - Julia `versioninfo()`:
> 
> ```julia
> Julia Version 1.11.3
> Commit d63adeda50d (2025-01-21 19:42 UTC)
> Build Info:
> Official https://julialang.org/ release
> Platform Info:
> OS: Linux (x86_64-linux-gnu)
> CPU: 20 × Intel(R) Core(TM) i9-10900X CPU @ 3.70GHz
> WORD_SIZE: 64
> LLVM: libLLVM-16.0.6 (ORCJIT, cascadelake)
> Threads: 20 default, 0 interactive, 10 GC (on 20 virtual cores)
> Environment:
> JULIA_NUM_THREADS = auto
> 
> ```

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [October 31, 2025, 8:15pm UTC](https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517/4 "2025-10-31T20:15:46Z")

</div>

It would help if you posted the full error message.

---

<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:** [October 31, 2025, 8:28pm UTC](https://discourse.julialang.org/t/simple-python-program-with-juliacall-segfaults/133517/5 "2025-10-31T20:28:24Z")

</div>

Here’s what I see:

```julia-auto
#> for i in {1..5}; do echo 50 | python juliacall_compute_square.py; done
julia version : 1.12.1
Enter a number
result: 2500
julia version : 1.12.1
Enter a number
result: 2500
Segmentation fault (core dumped) echo 50 | python juliacall_compute_square.py
julia version : 1.12.1
Enter a number
result: 2500
Segmentation fault (core dumped) echo 50 | python juliacall_compute_square.py
julia version : 1.12.1
Enter a number
result: 2500
Segmentation fault (core dumped) echo 50 | python juliacall_compute_square.py
julia version : 1.12.1
Enter a number
result: 2500

```

I got segfaults at the end of the 2nd, 3rd and 4th runs above, though all runs printed out the correct result 2500.
