Port flush() in Livebook not working

Hi all:

I have the following python code that outputs the right value while in iex, but I don’t get the output with same code in Livebook. I think it is something to do how stdout is set up, but I need help.

In iex, I get the following:

iex(1)> Port.open({:spawn, "python3 /Users/gani/Desktop/test.py 20 1000"}, [:binary])
iex(2)> flush()
{#Port<0.5>, {:data, "1573.1203851047762\n"}}

But the same code in Livebook gives me:

Port.open({:spawn, "python3 /Users/gani/Desktop/test.py 20 1000"}, [:binary]) #=> #Port<0.18>

flush() #=>** (CompileError) #cell:1: undefined function flush/0 (there is no such import)

What do I need to do to fix this?
Gani -

flush() isnt available in livebook i asssume. You can recursively get all messages sent by the port to the owner process using a receive.

flush is an IEx helper that calls receive and inspects the results:


Thank you @al2o3cr!


You can import the IEx helpers directly into the LiveBook and use them as normal.
add import IEx.Helpers, only: [flush: 0] to the ‘Notebook Setup and Dependencies’