You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed recently that julia will run the new @main entry point even after running an expression with the -e flag. This is a bit surprising. Consider the following workflow.
# runscript.jlusing MyPackage
config =generate_config()
function (@main)(args)
run_heavy_calculation(args)
end
This script can then be submitted e.g. via slurm for some production run. It would be really nice if I could do the following
julia -L runscript.jl -e "run_diagnostics(config)"
to do some sanity checks or print some configuration parameters without running the heavy calculation. However, in julia 1.11.3, @main will be run after run_diagnostics.
A workaround is to do julia -L runscript.jl -e "(@main)(_) = (run_diagnostics(config);0)". However, I would expect -e to behave like running julia -L runscript.jl and then entering the commands myself, which is clearly not the case. The same occurs with the -E flag, which is even more surprising.
Maybe changing this behavior would be a breaking change and we are stuck with it. Maybe it is surprising enough to be considered a bug that can be fixed?
The text was updated successfully, but these errors were encountered:
I think there's a question of what happens if you do -e include("runscript.jl"). Does main run? I think people probably expect it would because they'd expect it to be equivalent to running runscript.jl directly which does run main. I think this points to the problem being -L. I could see an argument for adding a special case that suppresses main when passed to -L (to facilitate precisely this use case), but it's a bit weird.
I think if -e 'include("runscript.jl"); do_something()' behaves differently from -L runscript.jl -e 'do_something()', it would be more confusing than the current situation.
An alternative solution would be to add a --nomain flag after all.
The other thing I can think of is that -e could be semantically considered as defining a main internally, so it would only run main if that main was defined inside -e. I think that could be acceptable.
I noticed recently that julia will run the new
@main
entry point even after running an expression with the-e
flag. This is a bit surprising. Consider the following workflow.This script can then be submitted e.g. via slurm for some production run. It would be really nice if I could do the following
to do some sanity checks or print some configuration parameters without running the heavy calculation. However, in julia 1.11.3,
@main
will be run afterrun_diagnostics
.A workaround is to do
julia -L runscript.jl -e "(@main)(_) = (run_diagnostics(config);0)"
. However, I would expect-e
to behave like runningjulia -L runscript.jl
and then entering the commands myself, which is clearly not the case. The same occurs with the-E
flag, which is even more surprising.Maybe changing this behavior would be a breaking change and we are stuck with it. Maybe it is surprising enough to be considered a bug that can be fixed?
The text was updated successfully, but these errors were encountered: