`Using` with Distributed

I noticed recently that when I try to do using for a package with worker processes, it appears to try loading it on all workers simultaneously, which creates some issues.

When I removed the worker processes and ran the save() method again, it worked fine. Is this a bug to report? I don’t know if I can reproduce it.

[ Info: Precompiling JLD2 [033835bb-8acc-5ee8-8aae-3f567f8a3819]
Error encountered while saving "output\\results.jld2".

Fatal error:
ERROR: LoadError: On worker 18:
SystemError: opening file "C:\\Users\\nicho\\.julia\\compiled\\v1.5\\JLD2\\O1EyT_oib2y.ji": Permission denied
#systemerror#49 at .\error.jl:168
#systemerror#48 at .\error.jl:167 [inlined]
systemerror at .\error.jl:167 [inlined]
#open#542 at .\iostream.jl:284
#open#543 at .\iostream.jl:346
open at .\iostream.jl:346 [inlined]
_require_from_serialized at .\loading.jl:732
_require at .\loading.jl:1040
require at .\loading.jl:928
#1 at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Distributed\src\Distributed.jl:78
#103 at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Distributed\src\process_messages.jl:290
run_work_thunk at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Distributed\src\process_messages.jl:79
run_work_thunk at C:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Distributed\src\process_messages.jl:88
#96 at .\task.jl:356

...and 2 more exception(s).

Stacktrace:
 [1] handle_error(::CompositeException, ::File{DataFormat{:JLD2}}) at C:\Users\nicho\.julia\packages\FileIO\2fEu2\src\error_handling.jl:82
 [2] handle_exceptions(::Array{Any,1}, ::String) at C:\Users\nicho\.julia\packages\FileIO\2fEu2\src\error_handling.jl:77
 [3] save(::Formatted, ::Any, ::Vararg{Any,N} where N; options::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\nicho\.julia\packages\FileIO\2fEu2\src\loadsave.jl:238
 [4] save at C:\Users\nicho\.julia\packages\FileIO\2fEu2\src\loadsave.jl:217 [inlined]
 [5] #save#19 at C:\Users\nicho\.julia\packages\FileIO\2fEu2\src\loadsave.jl:139 [inlined]
 [6] save(::String, ::String, ::Array{Array{Array{Array{Result,1},1},1},1}) at C:\Users\nicho\.julia\packages\FileIO\2fEu2\src\loadsave.jl:139
 [7] top-level scope at c:\Users\nicho\SMLMAssociationAnalysis_NCB.jl\src\paper\run_pos_control.jl:119
 [8] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091
 [9] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at .\essentials.jl:710
 [10] invokelatest(::Any, ::Any, ::Vararg{Any,N} where N) at .\essentials.jl:709
 [11] inlineeval(::Module, ::String, ::Int64, ::Int64, ::String; softscope::Bool) at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\eval.jl:185
 [12] (::VSCodeServer.var"#61#65"{String,Int64,Int64,String,Module,Bool,VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\eval.jl:144
 [13] withpath(::VSCodeServer.var"#61#65"{String,Int64,Int64,String,Module,Bool,VSCodeServer.ReplRunCodeRequestParams}, ::String) at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\repl.jl:124
 [14] (::VSCodeServer.var"#60#64"{String,Int64,Int64,String,Module,Bool,Bool,VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\eval.jl:142
 [15] hideprompt(::VSCodeServer.var"#60#64"{String,Int64,Int64,String,Module,Bool,Bool,VSCodeServer.ReplRunCodeRequestParams}) at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\repl.jl:36
 [16] (::VSCodeServer.var"#59#63"{String,Int64,Int64,String,Module,Bool,Bool,VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\eval.jl:110
 [17] with_logstate(::Function, ::Any) at .\logging.jl:408
 [18] with_logger at .\logging.jl:514 [inlined]
 [19] (::VSCodeServer.var"#58#62"{VSCodeServer.ReplRunCodeRequestParams})() at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\eval.jl:109
 [20] #invokelatest#1 at .\essentials.jl:710 [inlined]
 [21] invokelatest(::Any) at .\essentials.jl:709
 [22] macro expansion at c:\Users\nicho\.vscode\extensions\julialang.language-julia-1.0.10\scripts\packages\VSCodeServer\src\eval.jl:27 [inlined]
 [23] (::VSCodeServer.var"#56#57")() at .\task.jl:356
in expression starting at <mycode>

Does it help if you do using JLD2 before loading Distributed (to get it precompiled)?
I use Distributed like this:

using Pkg
Pkg.precompile()
# because Pkg.precompile() usually doesn't actually precompile everything:
using PackagesINeed 
using Distributed
Pkg.precompile()
addprocs(...)
@everywhere using PackagesINeed

It’s possibly an overkill, but for me it got rid of precompilation race conditions.

2 Likes