screen output problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ritesh Raj Sarraf

    #1

    screen output problem

    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.writ e(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

  • Calvin Spealman

    #2
    Re: screen output problem

    On 25 Nov 2006 15:27:26 -0800, Ritesh Raj Sarraf <rrs@researchut .comwrote:
    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.writ e(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
    >
    --

    >
    Take a look at this:


    --
    Read my blog! I depend on your acceptance of my opinion! I am interesting!

    Comment

    • Ritesh Raj Sarraf

      #3
      Re: screen output problem

      On Sunday 26 November 2006 13:07, Calvin Spealman wrote: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)

      iD8DBQBFbAU94Rh i6gTxMLwRAh5NAJ 0ZAkMF+ykF5OtDO Kta3MztRKJWeACb B0LZ
      cNEjxN1RqUWd4IO F+5QXHqo=
      =8FBd
      -----END PGP SIGNATURE-----

      Comment

      • Ritesh Raj Sarraf

        #4
        Re: screen output problem

        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
        <rrs@researchut .comdeclaimed the following in comp.lang.pytho n:
        >
        >
        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):
        >

        >
        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
        wlfraed@ix.netc om.com wulfraed@bestia ria.com

        (Bestiaria Support Staff: web-asst@bestiaria. com)
        HTTP://www.bestiaria.com/

        Comment

        Working...