Output-like print

In IJulia/Jupyter, print output (i.e. stdio output) and display output use different mechanisms.

STDOUT is flushed to the notebook display via “stream” output messages. This only happens at certain intervals — every print statement does not trigger an individual stream message.

Each display call, on the other hand, sends an individual “display_data” message. This is because display(x) output is not limited to text: for a given x, it outputs in the richest format supported by x and by Jupyter. e.g. it could output an image or a LaTeX-formatted equation.

As a result, display and print outputs do not necessarily appear in order.

In general, you cannot assume that display output goes to STDOUT, unlike print. e.g. display(x) may open up a separate window with an image, etcetera. display(x) means “show x in the best way you can for the current output device(s)”. If you want REPL-like text output that is guaranteed to go to STDOUT, use show(STDOUT, "text/plain", x) instead.

8 Likes