Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98618

Using subprocess to capture a progress line

From Tim Johnson <tim@akwebsoft.com>
Newsgroups comp.lang.python
Subject Using subprocess to capture a progress line
Date 2015-11-10 13:47 -0900
Organization AkWebsoft
Message-ID <mailman.224.1447196174.16136.python-list@python.org> (permalink)

Show all headers | View raw


Using python 2.7.6 on ubuntu 14.04 
The application in question is run with bash and gnome-terminal :

I've written a command-line "wrapper" for youtube-dl, executing
youtube-dl as a subprocess.

------------------------------------------------------------------
youtube-dl reports download progress on one line. I.E. the line is
overwritten numerous times with no carriage return until the
downloading is finished.
------------------------------------------------------------------

The following code runs the youtube-dl command and reports each line
as output by youtube-dl
###########
    p = subprocess.Popen(list(args), stderr=subprocess.STDOUT,
                         stdout=subprocess.PIPE)
    while True:
        line = p.stdout.readline()
        if not line:
            break
        tmp = line.strip()
        print tmp
###########

However this method not does show the download progress _until_ the
download is complete. 

To clarify : follows is output from my app running youtube-dl.
I've annotated the line in question with '###'

[youtube] ZIgnHPqp0Dk: Downloading webpage
[youtube] ZIgnHPqp0Dk: Downloading video info webpage
[youtube] ZIgnHPqp0Dk: Extracting video information
[youtube] ZIgnHPqp0Dk: Downloading js player en_US-vfljDEtYP
[youtube] ZIgnHPqp0Dk: Downloading DASH manifest
[download] Destination: Someday Soon - Judy Collins 1969.avi.m4a
### the line below is not seen until download is finished.
[download] 100% of 7.58MiB in 00:12.85KiB/s ETA 00:00
[ffmpeg] Correcting container in "Someday Soon - Judy Collins 1969.avi.m4a"
[ffmpeg] Destination: Someday Soon - Judy Collins 1969.avi.mp3
Deleting original file Someday Soon - Judy Collins 1969.avi.m4a (pass -k to keep)

Is there a way to code subprocess so the the progress is being
shown? In my case lines being output aren't being shown unless a
newline is sent, or so I understand it.

FYI : the need for this function in this case is trivial, but the
solution will be enlightening for me and have other uses, I'll bet.

thanks

-- 
Tim 
http://www.akwebsoft.com, http://www.tj49.com

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Using subprocess to capture a progress line Tim Johnson <tim@akwebsoft.com> - 2015-11-10 13:47 -0900

csiph-web