4

Currently, it takes a few seconds for the Julia interpreter to start on my machine when running any .jl file.

I'm wondering if there is a simple solution to this, such as a way to have a background pool of interpreters ready to execute scripts or a way to make the Julia repl, once opened, execute a .jl file (and possibly do so with the -p argument to properly handle multithreaded scripts) ?

3
  • If you could give a more specific description of your problem it would be easier to give a recommendation. You can consider passing commands to Julia running in the background via pipe. See stackoverflow.com/questions/48510815/… for an example (answer and comments to the answer). Commented May 4, 2018 at 18:07
  • 1
    Julia just isn't made for command line scripts yet. The most common workflow is to open up a session in the REPL/Juno/VSCode/Jupyter and keep it open. That never hits the startup time and allows interactive programming (which is essential anyways for data science and scientific computing). Commented May 4, 2018 at 18:28
  • I used to do something like this: gist.github.com/SalchiPapa/3b517d02a3e7e7a90d80 Commented May 4, 2018 at 21:25

1 Answer 1

3

I'm wondering if there is a simple solution to this, such as [...] a way to make the Julia repl, once opened, execute a .jl file [...].

You can execute a .jl file in a running Julia REPL with the include() function. For example, to execute a file foo.jl, enter the Julia REPL and do:

julia> include("test.jl")

The file will then be executed within the REPL. However, this is unlikely to solve your problem, since the file execution will probably take multiple seconds as well. The REPL itself starts quickly, the long execution time stems from Julia taking a long time to load the file.

You can partially address this issue with Revise.jl. Revise.jl is a Julia package that automatically and quickly reloads your imported files and packages when they are edited. Thus, you could mitigate your issue by only having to load the .jl file once at startup. Here is a quick example of using Revise.jl:

julia> Pkg.add("Example")
INFO: Installing Example v0.4.1
INFO: Package database updated

julia> using Revise        # importantly, this must come before `using Example`

julia> using Example

julia> hello("world")
"Hello, world"
3
  • Is there any way to use Revise AND execute the function with multiple julia processes (similar to the -p argument) ?
    – George
    Commented May 5, 2018 at 14:46
  • Yes, it should just work out of the box. I just did a quick test with Revise.jl and julia -p 4; worked flawlessly. Commented May 5, 2018 at 20:50
  • Ah... yeah, seems to work, I never realized the repl could be started with the -p arguments. thanks.
    – George
    Commented May 5, 2018 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.