# JuliaCall segmentation fault

**URL:** https://discourse.julialang.org/t/juliacall-segmentation-fault/80208
**Category:** General Usage
**Tags:** question
**Created:** [April 28, 2022, 12:31pm UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208 "2022-04-28T12:31:28Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)
#### Post date: [April 28, 2022, 12:31pm UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208/1 "2022-04-28T12:31:28Z")

</div>

I’ve got a Julia module (which contains compiled Fortran code) which is called in Python using JuliaCall ([Guide · PythonCall & JuliaCall](https://cjdoris.github.io/PythonCall.jl/dev/juliacall/)), for example within a Python script:

```julia
from juliacall import Main as jl
jl.seval(using MyModule.jl)

```

When I then call this in a Python function:

```julia

def mypythonfunction():
    Output = jl.MyModule.calc_something(args)

```

I get an instant segmentation fault (11), any ideas?

Edit: A note, this fails even when not using the compiled Fortran code and calling straight Julia code.

---

<div class="post-metadata">

### Author: ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)
#### Post date: [April 29, 2022, 6:47am UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208/2 "2022-04-29T06:47:54Z")

</div>

**Update** , this is also the same using PyJulia. As soon as I import the module in the global scope and try call it within a function it instantly segfaults.

I am at a loss!

---

<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: [April 29, 2022, 9:03pm UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208/3 "2022-04-29T21:03:53Z")

</div>

Can you post a MWE please.

---

<div class="post-metadata">

### Author: ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)
#### Post date: [April 30, 2022, 2:45am UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208/4 "2022-04-30T02:45:55Z")

</div>

Sure, my Julia module looks like this:

```julia
module myModule
    include("constants.jl")
end

```

where constants.jl is a simple dictionary:

```julia
molMassDict=Dict(
    "La"=> 162.9085,
    "Ce"=>172.1180,
    )

```

I then call it in Python using:

```julia
#!/usr/bin/env python3

from juliacall import Main as jl
jl.seval("using myModule")

def test_julia_import():
    print(jl.myModule.molMassDict)

test_julia_import()

```

Interestingly this MWE works no problem. The problem arises when I try to do this inside a Django (I’m not sure if you’re familiar with Django but it’s a Web Dev framework) view. A Django view is similarly a Python function, for example:

```julia
def django_view(request):
    test_julia()

```

if I call test\_julia() within this, it instantly segfaults:

```julia
signal (11): Segmentation fault
in expression starting at none:0
Allocations: 6828442 (Pool: 6825828; Big: 2614); GC: 8

```

Seems like it’s Django specific?

---

<div class="post-metadata">

### Author: ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)
#### Post date: [April 30, 2022, 3:25am UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208/5 "2022-04-30T03:25:46Z")

</div>

@cjdoris this is possibly related?

> [@Pyjulia, Django, and segfaults](https://discourse.julialang.org/t/pyjulia-django-and-segfaults/25313/7):
>
> Just speculating, but would it help to use locks on Python-side so that only one thread at a time calls Julia?

---

<div class="post-metadata">

### Author: ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)
#### Post date: [October 14, 2022, 9:47am UTC](https://discourse.julialang.org/t/juliacall-segmentation-fault/80208/6 "2022-10-14T09:47:06Z")

</div>

In case anyone comes here looking for answers, I’ve ended up moving the Julia code to it’s own microservice. The communication between Python and Julia is handled via requests ([requests · PyPI](https://pypi.org/project/requests/)) on the Python side and Genie on the Julia side.
