Detect if running as script


Does Julia have an equivalent to Python’s

if __name__ == "__main__":

Specifically, my problem is the following. I’m writing a standalone Julia script run_simulation.jl that does some computation and will ultimately run on a cluster. All the code in the script is in functions, including a function main(args), and the only line in the script that actually runs code is the last line


Now, during testing on small datasets, I’m getting a bit annoyed at the JIT-overhead. So, I’d rather run an interactive julia session, and do e.g.

julia> include("run_simulation.jl")
julia> main(["./runfolder"])

Then I can repeatedly run main without Julia recompiling.

This works if I comment out the last line of the script, but out of curiosity: can Julia detect whether it’s running as a script and should execute the main function, or whether it is included in the REPL (or another file)?


Would isinteractive do what you need?


Yes it would! Thanks!


Old x-ref:


Just be careful that it does not at all do the same thing as __name__ in python.