Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:48:54+00:00 2026-06-06T14:48:54+00:00

I am trying to implement this package http://code.google.com/p/python-progressbar/ when downloading a file like below:

  • 0

I am trying to implement this package http://code.google.com/p/python-progressbar/ when downloading a file like below:

    def dlProgress(count, blockSize, totalSize):
        widgets = ['Test: ', Percentage(), ' ', Bar(marker=RotatingMarker()), ' ', ETA(), ' ', FileTransferSpeed()]
        pbar = ProgressBar(widgets=widgets, maxval=totalSize).start()
        for count in range(totalSize):
            #print count
            pbar.update(int(count*blockSize*100/totalSize))
        pbar.finish()            
    urllib.urlretrieve(url, fileName, reporthook=dlProgress)

The problem is that the progress bar goes to 100% before the real download progress finished, and it continues to begin the new bar, like this:

Test: 100% |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Time: 0:00:31 402.06 kB/s
Test: 100% |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Time: 0:00:31 408.39 kB/s
Test: 100% |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Time: 0:00:32 389.47 kB/s
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:48:55+00:00Added an answer on June 6, 2026 at 2:48 pm

    You should initialize your progress bar outside of the progress callback. Then on the first time its called back, check and set the maxval and start it up:

    widgets = ['Test: ', Percentage(), ' ', Bar(marker=RotatingMarker()), ' ', ETA(), ' ', FileTransferSpeed()]
    pbar = ProgressBar(widgets=widgets)
    
    def dlProgress(count, blockSize, totalSize):
        if pbar.maxval is None:
            pbar.maxval = totalSize
            pbar.start()
    
        pbar.update(min(count*blockSize, totalSize))
    
    urllib.urlretrieve(url, fileName, reporthook=dlProgress)
    pbar.finish()
    

    As a side note, that last block will not be a full block, so you’ll want to make sure your not going over the totalSize.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement this example http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html and i have followed exactly all
I'm trying to implement the ringbuffer from this post https://stackoverflow.com/a/827749 and the only code
I'm following this guide: http://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html I just need to retrieve a token and use
I'm trying to implement this pattern in my WinForms application (I don't like it,
I am trying to implement this demo on my local machine. http://bit.ly/4g4o1r I have
I'm trying to implement this accepted solution for displaying a custom error message: https://stackoverflow.com/a/5229581/141172
Right, I'm trying to implement this game, http://www.helicoptergame.net/ , but I'm struggling with the
I am trying to implement something like this: Clicking on a link, a pop-up
I was trying to implement a tableview like this one please read the comment
I am tring to use http://code.google.com/p/dbmapper/ and I am not sure how to run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.