screen output problem

Discussion in 'Python' started by Ritesh Raj Sarraf, Nov 25, 2006.

  1. Hi,

    I have, for very long, been trying to find a consistent solution (which
    could work across major python platforms - Linux, Windows, Mac OS X)
    for the following problem.

    I have a function which downloads files from the web. I've made the
    function threaded. I'm trying to implement a progress bar for it which
    could work across all the platforms.

    The problem is that when the progress bar is displayed, all the threads
    overwrite the progress bar.

    I've thought of using curses but AFAIK curses is not available for
    Windows.

    Is there a generic way to accomplish the following:

    progress = "[===================]\n[=======================]"
    for x in range(5):
    sys.stdout.write(progress + "\r")

    Basically, I want a way through which I want to display data on two
    lines and make sure that "\r" overwrites the two lines without putting
    a newline making sure that whatever library it uses is available across
    all major Python platforms.

    Thanks,
    Ritesh
     
    Ritesh Raj Sarraf, Nov 25, 2006
    #1
    1. Advertising

  2. On 25 Nov 2006 15:27:26 -0800, Ritesh Raj Sarraf <> wrote:
    > Hi,
    >
    > I have, for very long, been trying to find a consistent solution (which
    > could work across major python platforms - Linux, Windows, Mac OS X)
    > for the following problem.
    >
    > I have a function which downloads files from the web. I've made the
    > function threaded. I'm trying to implement a progress bar for it which
    > could work across all the platforms.
    >
    > The problem is that when the progress bar is displayed, all the threads
    > overwrite the progress bar.
    >
    > I've thought of using curses but AFAIK curses is not available for
    > Windows.
    >
    > Is there a generic way to accomplish the following:
    >
    > progress = "[===================]\n[=======================]"
    > for x in range(5):
    > sys.stdout.write(progress + "\r")
    >
    > Basically, I want a way through which I want to display data on two
    > lines and make sure that "\r" overwrites the two lines without putting
    > a newline making sure that whatever library it uses is available across
    > all major Python platforms.
    >
    > Thanks,
    > Ritesh
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >


    Take a look at this:
    http://cheeseshop.python.org/pypi/progressbar

    --
    Read my blog! I depend on your acceptance of my opinion! I am interesting!
    http://ironfroggy-code.blogspot.com/
     
    Calvin Spealman, Nov 26, 2006
    #2
    1. Advertising

  3. On Sunday 26 November 2006 13:07, Calvin Spealman wrote:
    > Take a look at this:
    > http://cheeseshop.python.org/pypi/progressbar


    Hi,

    Sorry for being a little late in replying.

    The progressbar implementation is excellent but it has the same problems that
    the current progressbar implementation I use, has.

    In the above mentioned progressbar implementation also, the progressbar status
    is overwritten if you're using multiple threads.

    If your application is threaded, and multiple threads are downloading multiple
    files, you get a progressbar which is overwritten by all the 3 threads.

    I had brought this issue some time back too.
    Dennis Lee Bieber had a solution which looked better but not very much. His
    implementation had os.system(clear/cls) being called (to update the progress)
    which made the screen flicker if your network latency was low (especially in
    cases where the data is indirectly being downloaded from a Proxy or a product
    like NetApp's Netcache).

    If there's a way to print multiple lines of text withouth the newline ("\n")
    character, we can then use carriage return ("\r") and implement a proper
    progressbar with a bar for each separate progress action.

    Thanks,
    Ritesh
    --
    Ritesh Raj Sarraf
    RESEARCHUT - http://www.researchut.com
    "Necessity is the mother of invention."
    "Stealing logic from one person is plagiarism, stealing from many is
    research."
    "The great are those who achieve the impossible, the petty are those who
    cannot - rrs"

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.5 (GNU/Linux)

    iD8DBQBFbAU94Rhi6gTxMLwRAh5NAJ0ZAkMF+ykF5OtDOKta3MztRKJWeACbB0LZ
    cNEjxN1RqUWd4IOF+5QXHqo=
    =8FBd
    -----END PGP SIGNATURE-----
     
    Ritesh Raj Sarraf, Nov 28, 2006
    #3
  4. On Tue, 28 Nov 2006 15:15:28 +0530, Ritesh Raj Sarraf
    <> declaimed the following in comp.lang.python:


    > If there's a way to print multiple lines of text withouth the newline ("\n")
    > character, we can then use carriage return ("\r") and implement a proper
    > progressbar with a bar for each separate progress action.
    >

    If you were running on an Amiga, or via a serial port connection to
    an old VT-100 terminal, it would be child's play... Since both
    understood the same terminal control codes for moving the cursor around
    a text display.

    The old MS-DOS "ANSI" console driver may have understood that set.
    But M$, in its great and all-powerful wisdom, seems to feel that the
    only need for a command line interface is for batch configuration
    scripts that run with no human interaction, and hence with no need for
    status. One is expected to code a GUI instead if such things as
    progress-bars are needed.

    A google for "windows console cursor control" brings up (a bit of a
    surprise since I my search terms didn't mention Python):

    http://newcenturycomputers.net/projects/wconio.html

    Of course, this isn't portable to LINUX or other operating systems...

    Also, looking at win32api, I find a SetCursorPos() (and matching
    get...).

    --
    Wulfraed Dennis Lee Bieber KD6MOG

    HTTP://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
     
    Dennis Lee Bieber, Nov 28, 2006
    #4
  5. I'm not sure if there is a definite solution to this problem.

    I've noticed that one of the applications, which I use on a daily basis
    (apt from Debian) does address the progress bar issue in another way.

    When apt tries to download multiple files, it displays the progress of
    all the downloads on a single line. Probably the apt developers also
    might have run into the same issue and hence settled down with this
    workaround.


    Thanks,
    Ritesh


    Dennis Lee Bieber wrote:
    > On Tue, 28 Nov 2006 15:15:28 +0530, Ritesh Raj Sarraf
    > <> declaimed the following in comp.lang.python:
    >
    >
    > > If there's a way to print multiple lines of text withouth the newline ("\n")
    > > character, we can then use carriage return ("\r") and implement a proper
    > > progressbar with a bar for each separate progress action.
    > >

    > If you were running on an Amiga, or via a serial port connection to
    > an old VT-100 terminal, it would be child's play... Since both
    > understood the same terminal control codes for moving the cursor around
    > a text display.
    >
    > The old MS-DOS "ANSI" console driver may have understood that set.
    > But M$, in its great and all-powerful wisdom, seems to feel that the
    > only need for a command line interface is for batch configuration
    > scripts that run with no human interaction, and hence with no need for
    > status. One is expected to code a GUI instead if such things as
    > progress-bars are needed.
    >
    > A google for "windows console cursor control" brings up (a bit of a
    > surprise since I my search terms didn't mention Python):
    >
    > http://newcenturycomputers.net/projects/wconio.html
    >
    > Of course, this isn't portable to LINUX or other operating systems...
    >
    > Also, looking at win32api, I find a SetCursorPos() (and matching
    > get...).
    >
    > --
    > Wulfraed Dennis Lee Bieber KD6MOG
    >
    > HTTP://wlfraed.home.netcom.com/
    > (Bestiaria Support Staff: )
    > HTTP://www.bestiaria.com/
     
    Ritesh Raj Sarraf, Nov 29, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Russell
    Replies:
    1
    Views:
    377
    Steve C. Orr [MVP, MCSD]
    Jan 21, 2004
  2. chuck amadi
    Replies:
    1
    Views:
    493
    Larry Bates
    Jun 23, 2004
  3. Pat
    Replies:
    5
    Views:
    543
  4. owl
    Replies:
    2
    Views:
    882
  5. Mav
    Replies:
    22
    Views:
    367
Loading...

Share This Page