Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load module on remote workers from master (v2) #21695

Merged
merged 1 commit into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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