Skip to content

Commit e47a65e

Browse files
committed
document how to asynchronously launch workers
1 parent 1ffb6df commit e47a65e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

stdlib/Distributed/src/cluster.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,34 @@ the package `ClusterManagers.jl`.
359359
The number of seconds a newly launched worker waits for connection establishment from the
360360
master can be specified via variable `JULIA_WORKER_TIMEOUT` in the worker process's
361361
environment. Relevant only when using TCP/IP as transport.
362+
363+
To launch workers without blocking the REPL, or the containing function
364+
if launching workers programmatically, execute `addprocs` in its own task.
365+
366+
# Examples
367+
368+
```
369+
# On busy clusters, call `addprocs` asynchronously
370+
t = @async addprocs(...)
371+
```
372+
373+
```
374+
# Utilize workers as and when they come online
375+
if nprocs() > 1 # Ensure at least one new worker is available
376+
.... # perform distributed execution
377+
end
378+
```
379+
380+
```
381+
# Retrieve newly launched worker IDs, or any error messages
382+
if istaskdone(t) # Check if `addprocs` has completed to ensure `fetch` doesn't block
383+
if nworkers() == N
384+
new_pids = fetch(t)
385+
else
386+
fetch(t)
387+
end
388+
end
389+
```
362390
"""
363391
function addprocs(manager::ClusterManager; kwargs...)
364392
init_multi()

0 commit comments

Comments
 (0)