Skip to content
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

Evaluate imports first, other code second #76

Open
VarLad opened this issue Apr 29, 2024 · 4 comments
Open

Evaluate imports first, other code second #76

VarLad opened this issue Apr 29, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@VarLad
Copy link

VarLad commented Apr 29, 2024

MWE:

import Pkg, Malt
p = Malt.Worker()
j = Pkg.PackageSpec(name="Malt")

Malt.remote_eval_fetch(p, quote
    import Pkg;
    @info $j
end)

ERROR: Remote exception from Malt.Worker on port 9219 with PID 416219:

KeyError: key Base.PkgId(Base.UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f"), "Pkg") not found
Stacktrace:

This works perfectly in Julia 1.10.2
@savq Any idea what might be wrong here? I could also reproduce this with Distributed as well but for some reason the MWE with Distributed is working.

@VarLad
Copy link
Author

VarLad commented Apr 29, 2024

There was some discussion on Slack on how to fix this!
It can be found at:
https://julialang.slack.com/archives/C67910KEH/p1714389271264479

Some important headers:
An acceptable reason for this happening was given:

I think the reason this used to work was because Pkg was in the sysimage (which it is not on 1.11). Just using some other package:

import Example, Malt
p = Malt.Worker()
j = Example.domath

Malt.remote_eval_fetch(p, quote
    import Example
    $j
end)

gives the same error.

Distributed.jl has code where it looks up all the imports in a code block, executes that first, and then runs the code: https://github.com/JuliaLang/Distributed.jl/blob/3b889eecfdccb7febb9ae8abf9e3c604ffbc40ea/src/macros.jl#L197-L206 Perhaps Malt could do something like that as well?

@fonsp fonsp added the good first issue Good for newcomers label Apr 30, 2024
@fonsp
Copy link
Member

fonsp commented Apr 30, 2024

Thanks for the bug report and the helpful links! Could you save a copy of the slack conversation on github gist and share the link?

@VarLad
Copy link
Author

VarLad commented May 2, 2024

@fonsp Apologies for the late reply
Is this good enough or should I format better?

@fonsp fonsp added the enhancement New feature or request label Oct 30, 2024
@fonsp fonsp changed the title key not found in Julia 1.11beta2 Evaluate imports first, other code second Oct 30, 2024
@fonsp
Copy link
Member

fonsp commented Oct 30, 2024

Another good option is to improve the error message: for example:

  1. if there is a serialization error while sending the expression
  2. if it's a KeyError with Base.PkgId as key type
  3. then write "The expression to evaluate contains objects from package $x, but this package has not yet been imported on the worker."
  4. if the original expression contains import $x, then write "Try to first evaluate and wait for import $x, and then evaluate the rest of the expression."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants