JuliaLang / IJulia.jl

Julia kernel for Jupyter
MIT License
2.78k stars 409 forks source link

UndefVarError: execute_msg not defined #1077

Closed Jebrano closed 1 year ago

Jebrano commented 1 year ago

I'm simply trying to read a line using readline() but it return this following Stacktrace:

UndefVarError: execute_msg not defined

Stacktrace:
 [1] readprompt(prompt::String; password::Bool)
   @ VSCodeServer.IJuliaCore ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/IJuliaCore/src/stdio.jl:190
 [2] readprompt
   @ ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/IJuliaCore/src/stdio.jl:188 [inlined]
 [3] readline(io::VSCodeServer.IJuliaCore.IJuliaStdio{Base.PipeEndpoint, typeof(VSCodeServer.io_send_callback)})
   @ VSCodeServer.IJuliaCore ~/.vscode/extensions/julialang.language-julia-1.47.2/scripts/packages/IJuliaCore/src/stdio.jl:232
 [4] readline()
   @ Base ./io.jl:542
 [5] top-level scope
   @ ~/Documents/Julia/ThinkJU/src/ThinkJU.ipynb:1

I followed it and ended up with this function

function readprompt(prompt::AbstractString; password::Bool=false)
    # TODO DA
    if !execute_msg.content["allow_stdin"]
        error("IJulia: this front-end does not implement stdin")
    end
    send_ipython(raw_input[],
                 msg_reply(execute_msg, "input_request",
                           Dict("prompt"=>prompt, "password"=>password)))
    while true
        msg = recv_ipython(raw_input[])
        if msg.header["msg_type"] == "input_reply"
            return msg.content["value"]
        else
            error("IJulia error: unknown stdin reply")
        end
    end
end

I searched for execute_msg across the file and found this function that supposed to assign it the value msg and set it global but the function isn't called anywhere from what I have seen, it also have this comment with it

"""
Jupyter associates cells with message headers. Once a cell's execution state has
been set as to idle, it will silently drop stream messages (i.e. output to
stdout and stderr) - see https://github.com/jupyter/notebook/issues/518.
When using Interact, and a widget's state changes, a new
message header is sent to the IJulia kernel, and while Reactive
is updating Signal graph state, it's execution state is busy, meaning Jupyter
will not drop stream messages if Interact can set the header message under which
the stream messages will be sent. Hence the need for this function.
"""
function set_cur_msg(msg)
    global execute_msg = msg
end

so I tried to just comment if !execute_msg.content["allow_stdin"] from readprompt() but then also got hit with UndefVarError: raw_input not defined.

so I guess there is a bug with the way IJulia handles streams or with the readprompt() function, I don't know what to do next.

here is the output for versioninfo()

Julia Version 1.8.5
Commit 17cfb8e65e* (2023-01-08 06:45 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 1 on 8 virtual cores
Environment:
  JULIA_NUM_THREADS = 

I installed Julia from pamac "Offical Repo".

To reproduce the error just type readline().

Jebrano commented 1 year ago

turns out this is a duplicate of #2471 from the Julia-vscode extension.