pyjulia icon indicating copy to clipboard operation
pyjulia copied to clipboard

SIGSEGV 11 when interactively loading own Julia module

Open tanders opened this issue 4 years ago • 5 comments

I am trying to get a first simple example running with JuliaPy, loading a minimal Julia module into Python. Here is the Julia module:

module TestMod

export fn

function fn(x)
    x ^ 2
end

end

It is loaded and used by the following Python code.

from julia import Main
Main.include("/path/to/file.jl")
Main.TestMod.fn(3)

This works when calling non-interactively (i.e. if the first two lines of the above Python code are called together). However, if interactively I first excute the Python import statement and then afterwards the Main.include statement, I get the following.

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

I also get that crash when I try to otherwise access Main.TestMod.fn, e.g., by calling

fn = Main.TestMod.fn

Is this expected behaviour? I.e., is it not possible to load custom modules from given files one after the other?

Thank you!

PS: I tried this on a Mac (10.12.6) with Julia 1.1.1, the Python module julia-0.4.1 and the following Python version (running in PyCharm). '2.7.16 |Anaconda, Inc.| (default, Mar 14 2019, 16:24:02) \n[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]'

tanders avatar Aug 06 '19 11:08 tanders

Your code looks totally fine. It's hard to tell what is going on. You can start troubleshooting by:

  • Run julia.install(); sharing the full output can help.
  • Run julia.Julia(debug=True) in a fresh Python REPL.

Also, sharing full traceback (if any) is much more helpful than just a single line of the error message.

Edit: I meant julia.install() not julia.install(quiet=True).

tkf avatar Aug 06 '19 23:08 tkf

Thanks a lot for your support. OK, I now tried the following.

I loaded the code interactively again, line by line into a fresh Python REPL. The results are shown below this message. Note that there was no traceback, sorry, just the quick and sudden death of Python. Apologies that I cannot provide further information. What I find really strange, though (as said already) is that this occurs when python code is evaluated line by line, but not when the import and include statements are fed together to the interpreter.

Thanks again!

With julia.install(quiet=True):

>>> import julia
>>> julia.install(quiet=True)
>>> from julia import Main
>>> Main.include("/Users/torsten/Music_Informatics_Researcher_for_Aiva/Refining_musical_form/Julia/first_try.jl")
<PyCall.jlwrap Main.TestMod>
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

With julia.Julia(debug=True):

>>> import julia
>>> julia.Julia(debug=True)
DEBUG 
DEBUG Debug-level logging is enabled for PyJulia.
DEBUG PyJulia version: 0.4.1
DEBUG 
DEBUG pyprogramname = /miniconda3/envs/aiva/bin/python
DEBUG sys.executable = /miniconda3/envs/aiva/bin/python
DEBUG bindir = /Applications/Julia-1.1.app/Contents/Resources/julia/bin
DEBUG libjulia_path = /Applications/Julia-1.1.app/Contents/Resources/julia/lib/libjulia.1.1.dylib
DEBUG py_libpython = /miniconda3/envs/aiva/lib/libpython2.7.dylib
DEBUG jl_libpython = /miniconda3/envs/aiva/lib/libpython2.7.dylib
DEBUG use_separate_cache = False
DEBUG calling jl_init_with_image(/Applications/Julia-1.1.app/Contents/Resources/julia/bin, /Applications/Julia-1.1.app/Contents/Resources/julia/lib/julia/sys.dylib)
DEBUG seems to work...
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
<julia.core.LegacyJulia object at 0x11240c710>
>>> from julia import Main
DEBUG 
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
>>> Main.include("/Users/torsten/Music_Informatics_Researcher_for_Aiva/Refining_musical_form/Julia/first_try.jl")
DEBUG exception occured? None
DEBUG exception occured? None
DEBUG exception occured? None
<PyCall.jlwrap Main.TestMod>
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

tanders avatar Aug 07 '19 08:08 tanders

With julia.install(quiet=True):

Sorry, I meant julia.install(); I don't know why I put quiet=True there...

Did you use Ctrl-C in REPL? It is known to crash Python: https://pyjulia.readthedocs.io/en/latest/limitations.html#ctrl-c-does-not-work-terminates-the-whole-python-process

Or, do you use any special plugins? IPython < 7.0 is known to segfault so some REPL plugins could do the same. https://pyjulia.readthedocs.io/en/latest/troubleshooting.html#segmentation-fault-in-ipython

I strongly recommend using IPython 7.0 or later but it means to switch to Python 3 (which I strongly recommend as well whenever possible).

tkf avatar Aug 08 '19 05:08 tkf

I am experiencing the same issue and believe it's a Pycharm issue since the statement

from julia import Main

works with Ipython session under Spyder, VSCode. Also works with jupyterlab. I'm considering submitting a ticket to JetBrains. FWIW, my setup below

MacOS 10.15.3 PyCharm 2019.3.3 (Community Edition) PYTHON version 3.8.0 Julia Version 1.3.1 (2019-12-30) IPython 7.9.0 PyJulia version 0.5.1

lg-montoya avatar Feb 11 '20 18:02 lg-montoya

The same error on the Pycharm platform, not only from Julia import main, I have this error in all julia package import

yiruiliu110 avatar Sep 08 '20 15:09 yiruiliu110