Skip to content

Commit

Permalink
Issue 19960 - loading module on remote workers
Browse files Browse the repository at this point in the history
  • Loading branch information
GregPlowman authored and Plowman committed May 16, 2017
1 parent d7a5b5a commit 10c0746
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
10 changes: 8 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,14 @@ function _require_search_from_serialized(node::Int, mod::Symbol, sourcepath::Str
end

for path_to_try in paths::Vector{String}
if stale_cachefile(sourcepath, path_to_try)
continue
if node == myid()
if stale_cachefile(sourcepath, path_to_try)
continue
end
else
if @fetchfrom node stale_cachefile(sourcepath, path_to_try)
continue
end
end
restored = _require_from_serialized(node, mod, path_to_try, toplevel_load)
if isa(restored, Exception)
Expand Down
51 changes: 51 additions & 0 deletions test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -524,4 +524,55 @@ let module_name = string("a",randstring())
rm(file_name)
end

# Issue #19960
let
# ideally this would test with workers on a remote host that does not have access to the master node filesystem for loading
# can simulate this for local workers by using relative load paths on master node that are not valid on workers
# so addprocs before changing directory to temp directory, otherwise workers will inherit temp working directory

test_workers = addprocs(1)
temp_path = mktempdir()
save_cwd = pwd()
cd(temp_path)
load_path = mktempdir(temp_path)
load_cache_path = mktempdir(temp_path)
unshift!(LOAD_PATH, basename(load_path))
unshift!(Base.LOAD_CACHE_PATH, basename(load_cache_path))

ModuleA = :Issue19960A
ModuleB = :Issue19960B

write(joinpath(load_path, "$ModuleA.jl"),
"""
__precompile__(true)
module $ModuleA
export f
f() = myid()
end
""")

write(joinpath(load_path, "$ModuleB.jl"),
"""
__precompile__(true)
module $ModuleB
using $ModuleA
export g
g() = f()
end
""")

try
@eval using $ModuleB
for wid in test_workers
@test remotecall_fetch(g, wid) == wid
end
finally
shift!(LOAD_PATH)
shift!(Base.LOAD_CACHE_PATH)
cd(save_cwd)
rm(temp_path, recursive=true)
rmprocs(test_workers)
end
end

end # !withenv

0 comments on commit 10c0746

Please sign in to comment.