I was trying to better understand how Julia's Distributed library deals with remote executions of variables, and noticed that it is possible for a remote variable to change without being explicitly told so.
Consider this code:
using Distributed
addprocs(1)
@everywhere begin
a = myid()
println("After definition: ", a)
end
@everywhere begin
println("Inside @everywhere: ", a)
end
@fetchfrom 2 Core.eval(Main, :(println("Inside first remote eval: ", a)))
@fetchfrom 2 begin
println("Inside bare @fetchfrom: ", a)
end
@fetchfrom 2 Core.eval(Main, :(println("Inside second remote eval: ", a)))
Output:
After definition: 1
From worker 2: After definition: 2
Inside @everywhere: 1
From worker 2: Inside @everywhere: 2
From worker 2: Inside first remote eval: 2
From worker 2: Inside bare @fetchfrom: 1
From worker 2: Inside second remote eval: 1
After the @fetchfrom 2 begin ... end statement, the remote value of a changes from 2 to 1, even though there was no explicit assignment. The two remote evaluations before and after the change are exactly the same, yet they print different values for a.
I understand some of the issues that might cause the @fetchfrom statement to capture variables local to process 1, but don't see how this would cause an actual change to the value in process 2.