Get output of pv using python
<p>Is there a way to use the program pv from within python so as to get the progress of an operation?</p>

<p>So far I have the following:</p>

<pre><code>    p0 = sp.Popen(["pv", "-f", args.filepath],
                  bufsize=0,
                  stdout=sp.PIPE,
                  stderr=sp.PIPE)
    p1 = sp.Popen(["awk", "{print $1, $2, $1, $3, $4 }",  "{}".format(args.filepath)],
                   stdout=sp.PIPE,
                   stdin=p0.stdout)
</code></pre>

<p>But I'm having trouble getting continuous output from <code>p0</code>. I tried:</p>

<pre><code>    for line in p0.stderr:
        print("line:", line)
</code></pre>

<p>But this waits for the process to finish and then only prints the last progress report from <code>pv</code>. Does anybody know how I can get it to print the continuously updating status?</p>