JuliaPy / JuliaPy/pyjulia

Segfault when using pytest and FastAPI

Open
#521 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
893
Forks
101
PR merge metrics
No merged PRs in 30d

Description

I have a Python rest API (FastAPI) that calls julia functions.

When trying to run tests, I get the following error:

- In Ubuntu 20.04

```bash
test_test.py
signal (11): Segmentation fault
in expression starting at none:0
Allocations: 19557974 (Pool: 19550307; Big: 7667); GC: 24
Segmentation fault (core dumped)
```

- In Windows

```bash
self = src = '\n PyCall.pyfunctionret(\n (x) -> Base.eval(Main, :(spectra = $x)),\n Any,\n PyCall.PyAny)\n '
def _call(self, src):
"""
Low-level call to execute a snippet of Julia source.
This only raises an exception if Julia itself throws an error, but it
does NO type conversion into usable Python objects nor any memory
management. It should never be used for returning the result of Julia
expressions, only to execute statements.
"""
# logger.debug("_call(%s)", src)
> ans = self.api.jl_eval_string(src.encode('utf-8'))
E OSError: exception: access violation reading 0x0000000000000018
..\..\..\Anaconda3\envs\test\lib\site-packages\julia\core.py:554: OSError
============================================================================= short test summary info ==============================================================================
FAILED tests/test_prediction.py::test_prediction - OSError: exception: access violation reading 0x0000000000000018
================================================================================ 1 failed in 42.62s ================================================================================
```

How to reproduce:

```python
# main.py
from fastapi import FastAPI
from julia.api import Julia
jl = Julia(compiled_modules=False, debug=True)
from julia import Main

app = FastAPI()

@app.post("/test/")
def testtest():
jl.eval("println(cos(0))")
return 0
```

Test called with `pytest -s -p julia.pytestplugin --julia-compiled-modules=no`

```python
# test_test.py
from fastapi.testclient import TestClient
import json
from main import app

client = TestClient(app)

def test_prediction():
response = client.post("/test/")
print(response)
```

PyJulia 0.6.0
Python 3.9.5
Julia 1.7.2
pytest-7.2.0
pluggy-1.0.0

Any help is much appreciated!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.