How to use redirect_stdout in IJulia (Jupyter notebook)

The following redirect_stdout code works as expected in REPL

original_stdout = stdout
(rd, wr) = redirect_stdout()
println("123")
println("456")
redirect_stdout(original_stdout)
close(wr)
read(rd, String) 

The output is "123\n456\n".

However, if we paste the above code into IJulia (a Jupyter notebook), the last line read will block. Any suggestions on using redirect_stdout in IJulia?

julia> versioninfo()
Julia Version 1.5.0
Commit 96786e22cc (2020-08-01 23:44 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, sandybridge)
2 Likes

I’m experiencing the same issue. Would appreciate if anyone had a lead. I’m going to investigate more on that.

1 Like