Skip to content
Open
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
12 changes: 9 additions & 3 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ worker_timeout() = parse(Float64, get(ENV, "JULIA_WORKER_TIMEOUT", "60.0"))

## worker creation and setup ##
"""
start_worker([out::IO=stdout], cookie::AbstractString=readline(stdin); close_stdin::Bool=true, stderr_to_stdout::Bool=true)
start_worker([out::IO=stdout], cookie::AbstractString=readline(stdin); close_stdin::Bool=true, stderr_to_stdout::Bool=true,
exit_on_close::Bool=true, bind_addr=nothing)

`start_worker` is an internal function which is the default entry point for
worker processes connecting via TCP/IP. It sets up the process as a Julia cluster
Expand All @@ -253,15 +254,17 @@ The function reads the cookie from stdin if required, and listens on a free por
tasks to process incoming TCP connections and requests. It also (optionally)
closes stdin and redirects stderr to stdout.

If a specific interface is not specified through `--bind-to` it will make a
The interface to listen on is taken from `bind_addr` if it is set, otherwise
from the `--bind-to` command line option. If neither is given it will make a
best-effort attempt to pick the fastest available network interface to listen
on. The heuristics it uses for this depend on the system configuration and
should not be relied upon to always pick the fastest interface.

It does not return.
"""
start_worker(cookie::AbstractString=readline(stdin); kwargs...) = start_worker(stdout, cookie; kwargs...)
function start_worker(out::IO, cookie::AbstractString=readline(stdin); close_stdin::Bool=true, stderr_to_stdout::Bool=true, exit_on_close::Bool=true)
function start_worker(out::IO, cookie::AbstractString=readline(stdin); close_stdin::Bool=true, stderr_to_stdout::Bool=true,
exit_on_close::Bool=true, bind_addr=nothing)
init_multi()

if close_stdin # workers will not use it
Expand All @@ -271,6 +274,9 @@ function start_worker(out::IO, cookie::AbstractString=readline(stdin); close_std
stderr_to_stdout && redirect_stderr(stdout)

init_worker(cookie)
if !isnothing(bind_addr)
CTX[].lproc.bind_addr = bind_addr
end
interface = parse(IPAddr, CTX[].lproc.bind_addr)
if CTX[].lproc.bind_port == 0
(port, sock) = listenany(interface, CTX[].lproc.bind_port_hint)
Expand Down
7 changes: 4 additions & 3 deletions src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi
dir = params[:dir]
exename = params[:exename]
exeflags = params[:exeflags]
bind_to = manager.restrict ? `127.0.0.1` : `$(CTX[].lproc.bind_addr)`
bind_addr = manager.restrict ? "127.0.0.1" : CTX[].lproc.bind_addr
env = Dict{String,String}(params[:env])

# TODO: Maybe this belongs in base/initdefs.jl as a package_environment() function
Expand Down Expand Up @@ -539,14 +539,15 @@ function launch(manager::LocalManager, params::Dict, launched::Array, c::Conditi
Base.link_pipe!(pipe; reader_supports_async=true, writer_supports_async=true)

task = Threads.@spawn @with CTX => worker_ctx begin
start_worker(pipe.in, cookie; close_stdin=false, stderr_to_stdout=false, exit_on_close=false)
start_worker(pipe.in, cookie; close_stdin=false, stderr_to_stdout=false,
exit_on_close=false, bind_addr)
end
errormonitor(task)

wconfig.io = pipe.out
wconfig.userdata = (; ctx=worker_ctx, task, pipe)
else
cmd = `$(julia_cmd(exename)) $exeflags --bind-to $bind_to $(get_worker_arg())`
cmd = `$(julia_cmd(exename)) $exeflags --bind-to $bind_addr $(get_worker_arg())`
proc = open(detach(setenv(addenv(cmd, env), dir=dir)), "r+")

write_cookie(proc)
Expand Down
14 changes: 9 additions & 5 deletions src/precompile.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using PrecompileTools: @compile_workload

@compile_workload begin
# Run the workload in a separate ClusterContext so the default one stays clean
ClusterContext() do
# Use an in-process worker to avoid spawning a real process during precompilation
pid = only(addprocs(LocalManager(1, true, true)))
rmprocs(pid)
try
# Run the workload in a separate ClusterContext so the default one stays clean
ClusterContext() do
# Use an in-process worker to avoid spawning a real process during precompilation
pid = only(addprocs(LocalManager(1, true, true)))
rmprocs(pid)
end
catch ex
@error "DistributedNext precompilation failed, please report this" exception=(ex, catch_backtrace())
end
end
Loading