JuliaLang / julia

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

`@everywhere` running `using` and `imports` first means you can't do `using Pkg; Pkg.activate(".")` first before `using MyPkg` for local `MyPkg` #42085

Open vancleve opened 3 years ago

vancleve commented 3 years ago

When using Distributed and loading packages on workers that include local packages in development , one might want to do something like:

@everywhere begin
using Pkg; Pkg.activate(".")
using OtherPkgs
using MyPkg

where MyPkg is a local package in the current directory. However, since@everywhere moves using MyPkg above Pkg.activate(".") (see below) https://github.com/JuliaLang/julia/blob/a11de31665d46b63fe1ff043d056c3c5483afdc6/stdlib/Distributed/src/macros.jl#L204 this doesn't work and one is required to use two separate @everywhere blocks.

mgkuhn commented 3 years ago

If your workers are called via SSHManager, you could perhaps activate the environment via environment variables or command-line arguments, e.g. by passing one of these keyword parameter to addprocs: