Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when using pytest and FastAPI #521

Open
Immich opened this issue Jan 26, 2023 · 3 comments
Open

Segfault when using pytest and FastAPI #521

Immich opened this issue Jan 26, 2023 · 3 comments

Comments

@Immich
Copy link

Immich commented Jan 26, 2023

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
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
self = <julia.core.Julia object at 0x000002673F4D8220>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:

# 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

# 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!

@mkitti
Copy link
Member

mkitti commented Feb 27, 2023

On what operating system did this occur?

@Immich
Copy link
Author

Immich commented Mar 2, 2023

As mentioned in the output snippets:

  • Ubuntu 20.04
  • Windows 10

@mkitti
Copy link
Member

mkitti commented Mar 3, 2023

Does this occur with https://pypi.org/project/juliacall/ ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants