Skip to content

Commit 175ccb4

Browse files
authored
Merge pull request #11 from JuliaParallel/preferences
Document how to support different distributed worker backends
2 parents c68111a + 03bb8db commit 175ccb4

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ makedocs(;
3434
sitename = "DistributedNext",
3535
pages = [
3636
"DistributedNext" => "index.md",
37+
"support-preferences.md",
3738
"changelog.md"
3839
],
3940
warnonly = [:missing_docs, :cross_references],

docs/src/support-preferences.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Supporting both Distributed and DistributedNext
2+
3+
The [Distributed.jl](https://docs.julialang.org/en/v1/stdlib/Distributed/)
4+
standard library and DistributedNext are independent Julia modules, which means
5+
that they are not compatible at all. E.g. you cannot
6+
`DistributedNext.remotecall()` a worker added with `Distributed.addprocs()`. If
7+
you as a package developer want to make your package support both Distributed
8+
and DistributedNext, we suggest using
9+
[Preferences.jl](https://juliapackaging.github.io/Preferences.jl/stable/) to
10+
choose which package to load.
11+
12+
Here's an example for a package named Foo.jl:
13+
```julia
14+
module Foo
15+
16+
# Load a dependency which also supports Distributed/DistributedNext
17+
import Dependency
18+
19+
import Preferences: @load_preference, @set_preferences!
20+
21+
const distributed_package = @load_preference("distributed-package")
22+
if distributed_package == "DistributedNext"
23+
using DistributedNext
24+
elseif distributed_package == "Distributed"
25+
using Distributed
26+
else
27+
error("Unsupported `distributed-package`: '$(distributed_package)'")
28+
end
29+
30+
"""
31+
set_distributed_package!(value[="Distributed|DistributedNext"])
32+
33+
Set a [preference](https://github.com/JuliaPackaging/Preferences.jl) for using
34+
either the Distributed.jl stdlib or DistributedNext.jl. You will need to restart
35+
Julia after setting a new preference.
36+
"""
37+
function set_distributed_package!(value)
38+
# Set preferences for all dependencies
39+
Dependency.set_distributed_package!(value)
40+
41+
@set_preferences!("distributed-package" => value)
42+
@info "Foo.jl preference has been set, restart your Julia session for this change to take effect!"
43+
end
44+
45+
end
46+
```
47+
48+
Users will then be able to call
49+
e.g. `Foo.set_distributed_package!("DistributedNext")`. Note that
50+
`Foo.set_distributed_package!` should also set the preferences of any dependencies
51+
of Foo.jl that use a distributed worker package.

0 commit comments

Comments
 (0)