Skip to content

Commit

Permalink
Don't do bare using Foo
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge committed Feb 19, 2025
1 parent 17c58b2 commit 258409a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/ElasticClusterManager.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module ElasticClusterManager

using Distributed
using Sockets
# We don't do `using Foo`
# We either do `using Foo: bar`, or we do `import Foo`
# https://github.com/JuliaLang/julia/pull/42080

import Distributed
import Sockets
import Pkg

export launch, manage, kill, init_worker, connect
# Bring some names into scope, just for convenience:
using Distributed: launch, manage, kill, init_worker, connect

export launch, manage, kill, init_worker, connect
export ElasticManager, elastic_worker

import Distributed: launch, manage, kill, init_worker, connect

function worker_cookie()
Distributed.init_multi()
return Distributed.cluster_cookie()
Expand Down
12 changes: 6 additions & 6 deletions src/elastic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ else
my_errormonitor(t) = nothing
end

struct ElasticManager <: ClusterManager
active::Dict{Int, WorkerConfig} # active workers
pending::Channel{TCPSocket} # to be added workers
struct ElasticManager <: Distributed.ClusterManager
active::Dict{Int, Distributed.WorkerConfig} # active workers
pending::Channel{Sockets.TCPSocket} # to be added workers
terminated::Set{Int} # terminated worker ids
topology::Symbol
sockname
Expand All @@ -38,7 +38,7 @@ struct ElasticManager <: ClusterManager

t1 = @async begin
while true
let s = accept(l_sock)
let s = Sockets.accept(l_sock)
t2 = @async process_worker_conn(lman, s)
my_errormonitor(t2)
end
Expand Down Expand Up @@ -83,7 +83,7 @@ function process_pending_connections(mgr::ElasticManager)
while true
wait(mgr.pending)
try
addprocs(mgr; topology=mgr.topology)
Distributed.addprocs(mgr; topology=mgr.topology)
catch e
showerror(stderr, e)
Base.show_backtrace(stderr, Base.catch_backtrace())
Expand Down Expand Up @@ -144,7 +144,7 @@ function elastic_worker(cookie, addr="127.0.0.1", port=9009; stdout_to_master=tr
c = connect(addr, port)
write(c, rpad(cookie, HDR_COOKIE_LEN)[1:HDR_COOKIE_LEN])
stdout_to_master && redirect_stdout(c)
start_worker(c, cookie)
Distributed.start_worker(c, cookie)
end

function get_connect_cmd(em::ElasticManager; absolute_exename=true, same_project=true)
Expand Down
3 changes: 2 additions & 1 deletion test/elastic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# launch worker
old_cmd = ElasticClusterManager.get_connect_cmd(em)
new_cmd = `$(old_cmd) --coverage=user`
run(`sh -c $(new_cmd)`, wait=false)
# run(`sh -c $(new_cmd)`) # comment out this line when you are finished debugging
run(`sh -c $(new_cmd)`; wait=false) # uncomment this line when you are finished debugging

# wait at most TIMEOUT seconds for it to connect
@test :ok == timedwait(TIMEOUT) do
Expand Down

0 comments on commit 258409a

Please sign in to comment.