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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:32:08+00:00 2026-05-28T14:32:08+00:00

I want to make a multi-threaded downloader (in Python) and I need to tell

  • 0

I want to make a multi-threaded downloader (in Python) and I need to tell each thread where to start and how many bytes to download. For that I get the remote file size and divide it, for example, to 2. Now, let’s say that the remote file size is 5: when I divide the number to 2, I get 2 as result. Now I can start the download but I will lose a byte (because 2*2=4, not 5). I can’t use float numbers because I can’t download half of a byte. How I could divide that number and to get a list with [2, 3], for example?

  • 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-28T14:32:09+00:00Added an answer on May 28, 2026 at 2:32 pm

    Use divmod:

    >>> divmod(5, 2)
    (2, 1)
    >>>
    

    This tells you, that 5 divided by 2 is 2, remainder 1, so the last piece will be 2 + 1 = 3.

    >>> divmod(12345, 6)
    (2057, 3)
    

    Here, you’ll have 5 chunks at 2057 and a last slice at 2057+3.

    This algorithm will also work for cases, where division is without remainder:

    >>> divmod(12345, 5)
    (2469, 0)
    

    Here, you’ll have 4 chunks at 2469 plus a last slice at 2469+0.

    So, your chunk sizes could be computed as:

    def chunk_sizes(filesize, num_chunks):
        d, r = divmod(filesize, num_chunks)
        result = [d] * num_chunks
        result[-1] += r
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a multi-language site, such that all or almost all pages
So I have a test case that I want to make into a thread.
I am writing a multi-threaded application that mimics a movie theater. Each person involved
I want to make editable cells with multi-lines content in QTreeWidget and I use
I want to make an etag that matches what Apache produces. How does apache
I want to make a table in SqlServer that will add, on insert, a
I want to make an entity that has an autogenerated primary key, but also
I have a thread that sits in a blocking recv() loop and I want
Have an options table that i'm trying to make multi lingual with an English
I'm developing in python, still new to the game, and I want to make

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.