Skip to content

Commit 8ebd9bf

Browse files
committed
fixup! Add support for worker statuses
1 parent 54b4cf6 commit 8ebd9bf

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/cluster.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ not specified.
10141014
10151015
The callback will be called with the worker ID, the final
10161016
`Distributed.WorkerState` of the worker, and the last status of the worker as
1017-
set by [`setstatus`](@ref), e.g. `f(w::Int, state, status)`. `state` is an
1017+
set by [`setstatus!`](@ref), e.g. `f(w::Int, state, status)`. `state` is an
10181018
enum, a value of `WorkerState_terminated` means a graceful exit and a value of
10191019
`WorkerState_exterminated` means the worker died unexpectedly.
10201020
@@ -1210,7 +1210,7 @@ Identical to [`workers()`](@ref) except that the current worker is filtered out.
12101210
other_workers() = filter(!=(myid()), workers())
12111211

12121212
"""
1213-
setstatus(x, pid::Int=myid())
1213+
setstatus!(x, pid::Int=myid())
12141214
12151215
Set the status for worker `pid` to `x`. `x` may be any serializable object but
12161216
it's recommended to keep it small enough to cheaply send over a network. The
@@ -1223,22 +1223,22 @@ worker was last doing before it died.
12231223
12241224
# Examples
12251225
```julia-repl
1226-
julia> DistributedNext.setstatus("working on dataset 42")
1226+
julia> DistributedNext.setstatus!("working on dataset 42")
12271227
"working on dataset 42"
12281228
12291229
julia> DistributedNext.getstatus()
12301230
"working on dataset 42"
12311231
```
12321232
"""
1233-
function setstatus(x, pid::Int=myid())
1233+
function setstatus!(x, pid::Int=myid())
12341234
if pid procs()
12351235
throw(ArgumentError("Worker $(pid) does not exist, cannot set its status"))
12361236
end
12371237

12381238
if myid() == 1
12391239
@lock map_pid_statuses_lock map_pid_statuses[pid] = x
12401240
else
1241-
remotecall_fetch(setstatus, 1, x, myid())
1241+
remotecall_fetch(setstatus!, 1, x, myid())
12421242
end
12431243
end
12441244

@@ -1248,7 +1248,7 @@ _getstatus(pid) = @lock map_pid_statuses_lock get!(map_pid_statuses, pid, nothin
12481248
getstatus(pid::Int=myid())
12491249
12501250
Get the status for worker `pid`. If one was never explicitly set with
1251-
[`setstatus`](@ref) this will return `nothing`.
1251+
[`setstatus!`](@ref) this will return `nothing`.
12521252
"""
12531253
function getstatus(pid::Int=myid())
12541254
if pid procs()

test/distributed_exec.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Revise
44
using DistributedNext, Random, Serialization, Sockets
55
import DistributedNext
6-
import DistributedNext: launch, manage, getstatus, setstatus
6+
import DistributedNext: launch, manage, getstatus, setstatus!
77

88

99
@test cluster_cookie() isa String
@@ -1945,14 +1945,14 @@ end
19451945

19461946
# Test with the local worker
19471947
@test isnothing(getstatus())
1948-
setstatus("foo")
1948+
setstatus!("foo")
19491949
@test getstatus() == "foo"
19501950
@test_throws ArgumentError getstatus(2)
19511951

19521952
# Test with a remote worker
19531953
pid = only(addprocs(1))
19541954
@test isnothing(getstatus(pid))
1955-
remotecall_wait(setstatus, pid, "bar", pid)
1955+
remotecall_wait(setstatus!, pid, "bar", pid)
19561956
@test remotecall_fetch(getstatus, pid) == "bar"
19571957

19581958
rmprocs(pid)
@@ -2021,7 +2021,7 @@ end
20212021
last_status = nothing
20222022
exited_key = DistributedNext.add_worker_exited_callback((pid, state, status) -> (exit_state = state; last_status = status))
20232023
pid = only(addprocs(1))
2024-
setstatus("foo", pid)
2024+
setstatus!("foo", pid)
20252025

20262026
redirect_stderr(devnull) do
20272027
remote_do(exit, pid)

0 commit comments

Comments
 (0)