Stream: helpdesk (published)

Topic: `isinteractive()` and `.julia/config/startup.jl`


view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 18:08):

I'm confused. In my startup.jl I have @show isinteractive()

julia --banner=no
isinteractive() = false
julia> isinteractive()
true

julia>

and if I start a REPL in VS Code

isinteractive() = true
julia> isinteractive()
true

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 18:10):

I thought I didn't need to use atreplinit anymore, or something like that.

view this post on Zulip Expanding Man (Mar 25 2021 at 18:11):

It must have something to do with how VS code starts the Julia process. It might even be considered a bug in the VS code plugin because as far as I know the startup.jl is deliberately supposed to take place before the REPL initializes

view this post on Zulip Expanding Man (Mar 25 2021 at 18:12):

If I had to take a guess I would say that they are starting a "bare" Julia process, initializing the REPL, and then handling some other initialization on their own after that

view this post on Zulip Sebastian Pfitzner (Mar 25 2021 at 18:13):

I mean the session is interactive in both cases

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 18:13):

yeah, I expect the VS Code behavior honestly.

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 18:14):

What is the right way to do what I intend?

view this post on Zulip Expanding Man (Mar 25 2021 at 18:15):

My impression was that isinteractive() was supposed to be interpreted as "is this a running REPL?" rather than being a property of the run-time itself, though the documentation would seem to support your perspective

    isinteractive() -> Bool

Determine whether Julia is running an interactive session.

view this post on Zulip Expanding Man (Mar 25 2021 at 18:16):

I still seem to be using atreplinit(), my startup here

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 18:20):

thanks @Expanding Man . I was under the misguided impression that atreplinit(f) was "oldschool", but I think that was just because Revise can now hook into it itself.

view this post on Zulip Expanding Man (Mar 25 2021 at 18:21):

I do seem to recall someone saying that you shouldn't need atreplinit anymore, but at the moment it's not clear to me why that would be the case

view this post on Zulip Expanding Man (Mar 25 2021 at 18:22):

At least Revise claims not to need it however it does not rely on isinteractive() in an obvious way, so it may be advice that can't be generalized to other startup stuff

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 18:29):

@Sebastian Pfitzner do you believe the behavior with respect to isinteractive() in startup.jl should be consistent whether the REPL is run from my shell or from VS Code's terminal?

view this post on Zulip Sebastian Pfitzner (Mar 25 2021 at 18:30):

yes

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 21:43):

I think the difference just comes down to VS Code invoking julia with the -i flag

view this post on Zulip Gustavo Goretkin (Mar 25 2021 at 21:45):

BTW I commenting on this related issue: https://github.com/JuliaLang/julia/issues/10779

view this post on Zulip Sebastian Pfitzner (Mar 26 2021 at 09:01):

FWIW, we can't start Julia without -i because we also give a file to execute


Last updated: Nov 06 2024 at 04:40 UTC