JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.61k stars 5.48k forks source link

EXCEPTION_ACCESS_VIOLATION on PyCall occurs in a specific condition #50007

Open eisthf opened 1 year ago

eisthf commented 1 year ago

Problem description: EXCEPTION_ACCESS_VIOLATION occurs when I call a ScikitLearn python function. Specifically I have the following module called PyCallTest.jl. I placed it under some folder and added the path to LOAD_PATH so that now I load the module via using PyCallTest and call PyCallTest.test(). The error seems to have occurred at julia 'runtime kernel' level. So I report this issue here rather than to PyCall or ScikitLearn Github. There is one notable thing here: if I load the module via include("PyCallTest) then no error happens and the function executes as expected.

module PyCallTest

using ScikitLearn

@sk_import metrics: recall_score

function test()
    a = rand([0,1], 10)
    b = rand([0,1], 10)
    recall_score(a, b, labels=[0,1], pos_label=1)
end

end

Here is the error output from the console:

D:\Programs\julia-1.9.0\bin>julia
  Activating project at `E:\work\julia`
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.0 (2023-05-07)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using PyCallTest

julia> PyCallTest.test()

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ff8ef4dc1d5 -- PyObject_Call at D:\.julia\conda\3\python310.dll (unknown line)
in expression starting at REPL[2]:1
PyObject_Call at D:\.julia\conda\3\python310.dll (unknown line)
macro expansion at D:\.julia\packages\PyCall\twYvK\src\exception.jl:108 [inlined]
#107 at D:\.julia\packages\PyCall\twYvK\src\pyfncall.jl:43 [inlined]
disable_sigint at .\c.jl:473 [inlined]
__pycall! at D:\.julia\packages\PyCall\twYvK\src\pyfncall.jl:42 [inlined]
_pycall! at D:\.julia\packages\PyCall\twYvK\src\pyfncall.jl:29
_pycall! at D:\.julia\packages\PyCall\twYvK\src\pyfncall.jl:11
#_#114 at D:\.julia\packages\PyCall\twYvK\src\pyfncall.jl:86 [inlined]
PyObject at D:\.julia\packages\PyCall\twYvK\src\pyfncall.jl:86 [inlined]
test at E:\work\juliapkg\PyCallTest.jl:10
unknown function (ip: 000001f101ba80a3)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
do_call at C:/workdir/src\interpreter.c:126
eval_value at C:/workdir/src\interpreter.c:226
eval_stmt_value at C:/workdir/src\interpreter.c:177 [inlined]
eval_body at C:/workdir/src\interpreter.c:624
jl_interpret_toplevel_thunk at C:/workdir/src\interpreter.c:762
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:912
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:856
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:856
ijl_toplevel_eval at C:/workdir/src\toplevel.c:921 [inlined]
ijl_toplevel_eval_in at C:/workdir/src\toplevel.c:971
eval at .\boot.jl:370 [inlined]
eval_user_input at C:\workdir\usr\share\julia\stdlib\v1.9\REPL\src\REPL.jl:153
repl_backend_loop at C:\workdir\usr\share\julia\stdlib\v1.9\REPL\src\REPL.jl:249
#start_repl_backend#46 at C:\workdir\usr\share\julia\stdlib\v1.9\REPL\src\REPL.jl:234
start_repl_backend at C:\workdir\usr\share\julia\stdlib\v1.9\REPL\src\REPL.jl:231
#run_repl#59 at C:\workdir\usr\share\julia\stdlib\v1.9\REPL\src\REPL.jl:379
run_repl at C:\workdir\usr\share\julia\stdlib\v1.9\REPL\src\REPL.jl:365
jfptr_run_repl_62761.clone_1 at D:\Programs\julia-1.9.0\lib\julia\sys.dll (unknown line)
#1017 at .\client.jl:421
jfptr_YY.1017_37145.clone_1 at D:\Programs\julia-1.9.0\lib\julia\sys.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
jl_f__call_latest at C:/workdir/src\builtins.c:774
#invokelatest#2 at .\essentials.jl:816 [inlined]
invokelatest at .\essentials.jl:813 [inlined]
run_main_repl at .\client.jl:405
exec_options at .\client.jl:322
_start at .\client.jl:522
jfptr__start_34279.clone_1 at D:\Programs\julia-1.9.0\lib\julia\sys.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:1879 [inlined]
true_main at C:/workdir/src\jlapi.c:573
jl_repl_entrypoint at C:/workdir/src\jlapi.c:717
mainCRTStartup at C:/workdir/cli\loader_exe.c:59
BaseThreadInitThunk at C:\WINDOWS\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)
Allocations: 3937823 (Pool: 3934899; Big: 2924); GC: 6

As said, the call succeeds if I load the module via include

julia> include("E:/work/juliapkg/PyCallTest.jl")
Main.PyCallTest

julia> PyCallTest.test()
0.3333333333333333

Additional info:

julia> versioninfo()
Julia Version 1.9.0
Commit 8e63055292 (2023-05-07 11:25 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 12 × Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 8 on 12 virtual cores
Environment:
  JULIA_DEPOT_PATH = D:\.julia
  JULIA_PKG_SERVER = us-west.pkg.julialang.org      
  JULIA_SSL_CA_ROOTS_PATH = 
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 8

The julia program in use: 64-bit portable for Windows

giordano commented 1 year ago

@eisthf can you please try with a nightly build of Julia? Yesterday #50135 was merged and that solved some crashes in external libraries on Windows, I'm wondering if this can possibly be the same problem.