Consider a directory that contains only the following two files.
# one.jl
using Distributed
addprocs(4 - nprocs() + 1)
@everywhere begin
using Pkg
Pkg.activate(".")
using MAT
end
println("done")
# two.jl
using Distributed
addprocs(4 - nprocs() + 1)
@everywhere begin
using Pkg
Pkg.activate(".")
end
@everywhere using MAT
println("done")
(Note that the only difference between the two is where using MAT
occurs.)
I add MAT.jl to a new environment in the current directory with $ julia -e 'using Pkg; Pkg.activate("."); Pkg.add("MAT")'
.
Now, including one.jl from the REPL errors the first time (but then including it again works fine), but two.jl can be included from the REPL without any issues:
$ julia --project --banner=no
julia> include("one.jl")
ERROR: LoadError: On worker 2:
ArgumentError: Package MAT [23992714-dd62-5051-b70f-ba57cb901cac] is required but does not seem to be installed:
- Run `Pkg.instantiate()` to install all recorded dependencies.
Stacktrace:
[1] _require
@ ./loading.jl:1012
[2] require
@ ./loading.jl:936
[3] #1
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/Distributed.jl:79
[4] #103
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:274
[5] run_work_thunk
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:63
[6] run_work_thunk
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/process_messages.jl:72
[7] #96
@ ./task.jl:411
...and 3 more exceptions.
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base ./task.jl:369
[2] macro expansion
@ ./task.jl:388 [inlined]
[3] _require_callback(mod::Base.PkgId)
@ Distributed /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/Distributed.jl:76
[4] #invokelatest#2
@ ./essentials.jl:708 [inlined]
[5] invokelatest
@ ./essentials.jl:706 [inlined]
[6] require(uuidkey::Base.PkgId)
@ Base ./loading.jl:942
[7] require(into::Module, mod::Symbol)
@ Base ./loading.jl:923
[8] top-level scope
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/macros.jl:204
[9] include(fname::String)
@ Base.MainInclude ./client.jl:444
[10] top-level scope
@ REPL[1]:1
in expression starting at /home/steven/tmp/one.jl:4
julia> include("one.jl")
Activating environment at `~/tmp/Project.toml`
From worker 3: Activating environment at `~/tmp/Project.toml`
From worker 4: Activating environment at `~/tmp/Project.toml`
From worker 2: Activating environment at `~/tmp/Project.toml`
From worker 5: Activating environment at `~/tmp/Project.toml`
done
$ julia --project --banner=no
julia> include("two.jl")
Activating environment at `~/tmp/Project.toml`
From worker 3: Activating environment at `~/tmp/Project.toml`
From worker 5: Activating environment at `~/tmp/Project.toml`
From worker 4: Activating environment at `~/tmp/Project.toml`
From worker 2: Activating environment at `~/tmp/Project.toml`
done
Can someone please explain why one.jl fails but two.jl does not? And why one.jl fails only once in a Julia session?
Thanks in advance!
EDIT: I’m using Julia 1.6.2, but I see the same behavior on 1.6.1.