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 7435903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:09:11+00:00 2026-05-29T10:09:11+00:00

I am currently getting an md5 checksum as follows: >>> import hashlib >>> f

  • 0

I am currently getting an md5 checksum as follows:

>>> import hashlib
>>> f = open(file)
>>> m = hashlib.md5()
>>> m.update(f.read())
>>> checksum = m.hedxigest()

I need to return the checksum of a large video file, that will take several minutes to generate. How would I implement a percentage counter, such that it prints the percentage complete for each percentage while it is running. Something like:

>>> checksum = m.hedxigest()
1% done...
2% done...
etc.
  • 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-05-29T10:09:12+00:00Added an answer on May 29, 2026 at 10:09 am

    You can call the update() method repeatedly and feed the file in chunks to it. Thus, you can show the progress yourself.

    import hashlib
    import os
    
    def digest_with_progress(filename, chunk_size):
        read_size = 0
        last_percent_done = 0
        digest = hashlib.md5()
        total_size = os.path.getsize(filename)
    
        data = True
        f = open(filename)
        while data:
            # Read and update digest.
            data = f.read(chunk_size)
            read_size += len(data)
            digest.update(data)
    
            # Calculate progress.
            percent_done = 100 * read_size / total_size
            if percent_done > last_percent_done:
                print '%d%% done' % percent_done
                last_percent_done = percent_done
        f.close()
        return digest.hexdigest()
    

    When I try print digest_with_progress('/bin/bash', 1024) this is what I get:

    1% done
    2% done
    3% done
    4% done
    5% done
    6% done
    7% done
    8% done
    9% done
    10% done
    11% done
    12% done
    13% done
    14% done
    15% done
    16% done
    17% done
    18% done
    19% done
    20% done
    21% done
    22% done
    23% done
    24% done
    25% done
    26% done
    27% done
    28% done
    29% done
    30% done
    31% done
    32% done
    33% done
    34% done
    35% done
    36% done
    37% done
    38% done
    39% done
    40% done
    41% done
    42% done
    43% done
    44% done
    45% done
    46% done
    47% done
    48% done
    49% done
    50% done
    51% done
    52% done
    53% done
    54% done
    55% done
    56% done
    57% done
    58% done
    59% done
    60% done
    61% done
    62% done
    63% done
    64% done
    65% done
    66% done
    67% done
    68% done
    69% done
    70% done
    71% done
    72% done
    73% done
    74% done
    75% done
    76% done
    77% done
    78% done
    79% done
    80% done
    81% done
    82% done
    83% done
    84% done
    85% done
    86% done
    87% done
    88% done
    89% done
    90% done
    91% done
    92% done
    93% done
    94% done
    95% done
    96% done
    97% done
    98% done
    99% done
    100% done
    b114ecaab65bc5b02f5a129bd29d1864
    

    Here are the actual details of this file.

    $ ls -l /bin/bash; md5sum /bin/bash
    -rwxr-xr-x 1 root root 971384 Nov 30 16:31 /bin/bash
    b114ecaab65bc5b02f5a129bd29d1864  /bin/bash
    

    Note that, you would not get the expected output if you make chunk_size too large. For example if we read in 100 KB chunks instead of 1 KB chunks for /bin/bash, this is what you see.

    10% done
    21% done
    31% done
    42% done
    52% done
    63% done
    73% done
    84% done
    94% done
    100% done
    b114ecaab65bc5b02f5a129bd29d1864
    

    The limitation of this approach is that we calculate the progress only after we have read a chunk into the digest. So, if the chunk size is too large, the percentage-difference in progress would be more than 1% every time you read a chunk and update the digest. A bigger chunk size would get the job done a bit quicker. So, you might want to relax the condition of printing percentage complete for each percentage in favour of efficiency.

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

Sidebar

Related Questions

afile is a previously existing file. handle=open(afile,'r+b') data=handle.readline() handle.close() # signgenerator is a hashlib.md5()
I'm currently getting to know Java and OSGi, so I've read a few books.
I'm currently getting my feet wet with Win CE 5.0 to update some code
Hey everyone I am currently getting the next variable based on if a file
I'm currently getting user input from a very large form as an XML document.
I'm currently getting user input from a very large form as an XML document.
I am currently getting a file list from an OpenFileDialog and adding then into
I'm currently getting the user's birthday from Facebook and storing it in the standard
I'm currently getting a site designed by a person who works in photoshop and
I'm currently getting to grips with mod_rewrite and have ran into a stumbling block

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.