# Flush print on Paraview Python Shell

**URL:** https://discourse.paraview.org/t/flush-print-on-paraview-python-shell/3574
**Category:** ParaView Support
**Tags:** python
**Created:** [February 16, 2020, 8:40am UTC](https://discourse.paraview.org/t/flush-print-on-paraview-python-shell/3574 "2020-02-16T08:40:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![limliangjin](https://discourse.paraview.org/user_avatar/discourse.paraview.org/limliangjin/32/3917_2.png) [@limliangjin](https://discourse.paraview.org/u/limliangjin)
#### Post date: [February 16, 2020, 8:41am UTC](https://discourse.paraview.org/t/flush-print-on-paraview-python-shell/3574/1 "2020-02-16T08:41:00Z")

</div>

While running python code in the Paraview Python Shell, I found that the print output is flushed only after all the statements are completed.  
For example I have this simple loop that prints something:  
`
for i in range(0, 10):
print(i)
sleep(1)
`

The shell freezes for 10 seconds, and print out everything at once, while I would expect the shell prints them out each second.

This eventually affects my python script, as I am running something that takes time, and I would like to print out the progress using print function.

---

<div class="post-metadata">

### Author: ![Kenneth\_Moreland](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kenneth_moreland/32/15033_2.png) [@Kenneth\_Moreland](https://discourse.paraview.org/u/Kenneth_Moreland)
#### Post date: [February 17, 2020, 6:02am UTC](https://discourse.paraview.org/t/flush-print-on-paraview-python-shell/3574/2 "2020-02-17T06:02:59Z")

</div>

I think this question is more about Python than ParaView. Like many I/O systems, the Python I/O system implementing `print` uses buffering. So things sent to `print` may not be actually printed right away but may sit in a buffer to be queued later.

You can find information about flushing Python’s `print` buffer in other Python forms such as [this Stack Overflow post](https://stackoverflow.com/questions/230751/how-to-flush-output-of-print-function).

The short answer is that you can use `sys.stdout.flush()` to force what you sent to `print` to be outputted to the console. It would look something like this:

```auto
import sys

for i in range(0, 10):
    print(i)
    sys.stdout.flush()
    sleep(1)

```

---

<div class="post-metadata">

### Author: ![limliangjin](https://discourse.paraview.org/user_avatar/discourse.paraview.org/limliangjin/32/3917_2.png) [@limliangjin](https://discourse.paraview.org/u/limliangjin)
#### Post date: [February 17, 2020, 6:21am UTC](https://discourse.paraview.org/t/flush-print-on-paraview-python-shell/3574/3 "2020-02-17T06:21:12Z")

</div>

Thanks for the reply.

However, I did try to flush using the method you explained and `print(i, flush=True)`, both do not mitigate the issue. The shell still shows the output after the end of the execution. During the waiting time, the shell is not responding.
