Start repl from non-interactive session

Hi, I cannot find this question elsewhere. I want to be able to start the REPL from a julia script if a certain condition occurs (for debugging purpose/fixing bugs live) without having to include(“program.jl”) directly from the REPL.

Something like importing Base.REPL, but don’t know which function to call to set it up.

Thanks, Nicolò

1 Like

Basic example:

using Base: REPL, Terminals

term = Base.Terminals.TTYTerminal(get(ENV, "TERM", @static is_windows() ? "" : "dumb"), STDIN, STDOUT, STDERR)
active_repl = REPL.LineEditREPL(term, true)
REPL.run_repl(active_repl, backend->(global active_repl_backend = backend))

See _start in base/client.jl for how to set up history (and other options).


Cool, many thanks!
How to “continue” (close it without exiting the program?). It works with CTRL-d but which is the command it’s sending?

Thanks again, Nicolò

You’d probably have to throw an error to the backend task. I’m not sure how to do that off-hand, but I’ll take a look when I get a chance (if no one else has an answer).

doesn’t just exit() work?

no, because it will exit everything.
ie. if you have
#snippet from ihnorton
println(“running this line”)

Pressing ctrl-D will show “running this line”, while exit() will not