-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to support different distributed worker backends #11
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Supporting both Distributed and DistributedNext | ||
|
||
The [Distributed.jl](https://docs.julialang.org/en/v1/stdlib/Distributed/) | ||
standard library and DistributedNext are independent Julia modules, which means | ||
that they are not compatible at all. E.g. you cannot | ||
`DistributedNext.remotecall()` a worker added with `Distributed.addprocs()`. If | ||
you as a package developer want to make your package support both Distributed | ||
and DistributedNext, we suggest using | ||
[Preferences.jl](https://juliapackaging.github.io/Preferences.jl/stable/) to | ||
choose which package to load. | ||
|
||
Here's an example for a package named Foo.jl: | ||
```julia | ||
module Foo | ||
|
||
# Load a dependency which also supports Distributed/DistributedNext | ||
import Dependency | ||
|
||
import Preferences: @load_preference, @set_preferences! | ||
|
||
const distributed_package = @load_preference("distributed-package") | ||
if distributed_package == "DistributedNext" | ||
using DistributedNext | ||
elseif distributed_package == "Distributed" | ||
using Distributed | ||
else | ||
error("Unsupported `distributed-package`: '$(distributed_package)'") | ||
end | ||
|
||
""" | ||
set_distributed_package!(value[="Distributed|DistributedNext"]) | ||
|
||
Set a [preference](https://github.com/JuliaPackaging/Preferences.jl) for using | ||
either the Distributed.jl stdlib or DistributedNext.jl. You will need to restart | ||
Julia after setting a new preference. | ||
""" | ||
function set_distributed_package!(value) | ||
# Set preferences for all dependencies | ||
Dependency.set_distributed_package!(value) | ||
|
||
@set_preferences!("distributed-package" => value) | ||
@info "Foo.jl preference has been set, restart your Julia session for this change to take effect!" | ||
end | ||
|
||
end | ||
``` | ||
|
||
Users will then be able to call | ||
e.g. `Foo.set_distributed_package!("DistributedNext")`. Note that | ||
`Foo.set_distributed_package!` should also set the preferences of any dependencies | ||
of Foo.jl that use a distributed worker package. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 03bb8db.