JuliaLang / julia

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

"sysimg.jl" raises error when "userimg.jl" prints to `STDOUT` #18448

Closed xqrongm closed 8 years ago

xqrongm commented 8 years ago

I tried to build a custom system image with this command: build_sysimg(sysimg_path, "native", usrimg_path)

Whenever I include code in the usrimg_path file (used as "userimg.jl" by "sysimg.jl") that prints to STDOUT like: println("something") @time 1+1

An error will be raised like below. I don't understand the point of this design. It's more of an inconvenience to me than anything else, because I want to include in "userimg.jl" code that prints to STDOUT which I can't suppress.

C:\Program Files\Julia-0.4.6\share\julia\base\precompile.jl error during bootstrap: LoadError(at "sysimg.jl" line 319: LoadError(at "C:\Program Files\Julia-0.4.6\share\julia\base\userimg.jl" line 158: Und efVarError(var=:STDOUT))) jl_unprotect_stack at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_throw at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_undefined_var_error at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) time_print at util.jl:112 jlcall_time_print_22764 at (unknown line) jl_apply_generic at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_expr at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_thunk_with at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_expr_in at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_thunk_with at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_eval_with_compiler_p at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_parse_eval_all at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jlload at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) include at boot.jl:261 jl_apply_generic at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) include_from_node1 at loading.jl:320 jl_apply_generic at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_expr at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_thunk_with at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_interpret_toplevel_expr_in at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_toplevel_eval_body at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_eval_with_compiler_p at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_parse_eval_all at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_load at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) unknown function (ip: 00000000004015BE) unknown function (ip: 0000000000401AE5) unknown function (ip: 00000000004028AB) unknown function (ip: 000000000040140C) unknown function (ip: 000000000040153B) BaseThreadInitThunk at C:\WINDOWS\system32\KERNEL32.DLL (unknown line) RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)

ERROR: failed process: Process('C:\Program Files\Julia-0.4.6\bin\julia' -C native --output-ji E:/freelance/applications /010_qpcr/Julia/for_sysimg/0_test/sys0_test.ji --output-o E:/freelance/applications/010_qpcr/Julia/for_sysimg/0_test/sys 0_test.o -J E:/freelance/applications/010_qpcr/Julia/for_sysimg/0_test/inference.ji --startup-file=no sysimg.jl, Proces sExited(1)) [1] in run at process.jl:531

tkelman commented 8 years ago

Fixed in 0.5, not likely to be backported.

xqrongm commented 8 years ago

I'm not sure if this is a related issue or not.

Using the same command to build a custom system image with this command: build_sysimg(sysimg_path, "native", usrimg_path)

When I include this snippet of code in the usrimg_path file (used as "userimg.jl" by "sysimg.jl"):

module test
    using MySQL
    db_conn = mysql_connect("localhost", "root1", "pswd1", "test_1ch")
    ms_df = mysql_execute(db_conn, "select * from steps where id=2") # No. 1
    function __init__()
        ms_df = mysql_execute(db_conn, "select * from steps where id=2") # No. 2
    end
end # test

The image was built successfully. But when I start Julia REPL with the image, it raises the following error below. I think No. 1 ms_df = didn't raise error but No. 2 ms_df = did. Again I don't understand the point of this design.

PS C:\WINDOWS\system32> julia -J E:/freelance/applications/010_qpcr/Julia/for_sysimg/0_test/sys0_test.dll fatal: error thrown and no exception handler available. Base.InitError(mod=:test, error=MySQL.MySQLInterfaceError(msg="Method called with null connection.")) jl_unprotect_stack at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_throw at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) mysql_execute at E:\for_programs\julia_pkgs\v0.4\MySQL\src\handy.jl:144 jlcall_mysql_execute#692___520 at (unknown line) jl_applygeneric at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) init at C:\Program Files\Julia-0.4.6\share\julia\base\userimg.jl:17 jlcallinit___519 at (unknown line) jl_apply_generic at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_module_run_initializer at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_init_restored_modules at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) jl_get_builtin_hooks at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) julia_init at C:\Program Files\Julia-0.4.6\bin\libjulia.dll (unknown line) unknown function (ip: 000000000040289F) unknown function (ip: 000000000040140C) unknown function (ip: 000000000040153B) BaseThreadInitThunk at C:\WINDOWS\system32\KERNEL32.DLL (unknown line) RtlUserThreadStart at C:\WINDOWS\SYSTEM32\ntdll.dll (unknown line)

vtjnash commented 8 years ago

please see the documentation: http://docs.julialang.org/en/latest/manual/modules/#module-initialization-and-precompilation

xqrongm commented 8 years ago

I can use using or reload to load this module without error. The error only happens when I try to embed it using "build_sysimg.jl". I can't find an answer in your link. Can you point it out to me?

timholy commented 8 years ago

To debug faster, first try making it precompilable. Once that works, you'll have much faster progress towards getting it working with userimg.jl.

As a hint, it seems rather likely that the initialization of db_conn is the problem.

xqrongm commented 8 years ago

I guess the problem is that package "MySQL" doesn't use __precompile()__, so I can't build my code into custom system image if I use "MySQL".

If that's true, it'll be helpful to explicitly states in the documentation for System Image Building (http://docs.julialang.org/en/release-0.4/devdocs/sysimg/) that "To build a module into a custom system image, precompile() should not be used in the module unless all of its dependencies are also using precompile(). Failure to do so can result in a runtime error when loading the module." as it is in http://docs.julialang.org/en/latest/manual/modules/#module-initialization-and-precompilation

StefanKarpinski commented 8 years ago

This should probably be reopened as a doc issue then. I'm on mobile now so if someone could do that, it would be appreciated.

yuyichao commented 8 years ago

Is this not fixed on 0.5?