Print to terminal instead of to Jupyter Notebook

I have a function that does some calculation and prints the ongoing progress, say

function f()
    for i in 1:10
        sleep(0.1)
        println(i) 
    end    
end

When running it in a Jupyter Notebook, the output cell soon gets cluttered. So I would like to forward this output to the terminal from where I launched the Jupyter Notebook, in the same way that when you run ] add Package in a Jupyter Notebook, you get the progress information on the terminal.

Thanks a lot!

PS: ProgressMeter is amazing and the output very concise but it wouldn’t suit my needs, I need more detailed information of what’s going on inside the computation.

You may try something like

println(IJulia.orig_stdout[], "testing...")

ref

3 Likes

This might not be the solution you’re thinking of, but you could switch to using Pluto notebooks where things like println print to the terminal by default. The package PlutoUI also provides a handy with_terminal function that allows you to print within the notebook when you want that as well.

1 Like

Works like a charm. Thanks so much!

Hi, thanks a lot for the suggestion. I love Pluto notebooks, my reason to use Jupyter was that, at least when I started developing this code, Pluto didn’t support Revise.jl, which is very important for me since I make changes to the source files often. But it seems that they might have gotten the support since? (https://github.com/fonsp/Pluto.jl/issues/238)

I might have to give it a try! :slight_smile: