JuliaLang / JuliaLang/Distributed.jl

World age problems when using @everywhere in a function

Open
#156 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
55
Forks
19
PR merge metrics
No merged PRs in 30d

Description

I have a julia (1.12) file that is structured something like this:


using Distributed

function main()
  @everywhere variable = [0, 1, 2, 3, 4, 5]

  for x in variable
    println(x^2)
  end
end

main()

From my understanding @everywhere should define the variable on every worker, including the main process.
But when I run the code, it give me this error:
UndefVarError: `variable` not defined in `Main` The binding may be too new: running in world age 38716, while current world is 38717.

In a jupyter notebook, I can run main() again a second time, and then it works, since I assume then the world age matches...

Can someone explain what is going on and if there is some way to circumvent this problem? I can fix it by defining it again in the main process variable = [0, 1, 2, 3, 4, 5], or by taking the code out of the main() function but to me that doesn't feel intended.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Julia 1.12 reproducer in issue #156, focusing on @everywhere inside main() and the second invocation behavior. Compare execution from a script with the Jupyter notebook case. Done should mean the world-age behavior is explained and a supported way to avoid the failure is identified or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.