File downloading using python with threads

后端 未结 4 798
一生所求
一生所求 2021-01-03 19:09

I\'m creating a python script which accepts a path to a remote file and an n number of threads. The file\'s size will be divided by the number of threads, when each thread c

4条回答
  •  执念已碎
    2021-01-03 19:35

    You need to fetch completely separate parts of the file on each thread. Calculate the chunk start and end positions based on the number of threads. Each chunk must have no overlap obviously.

    For example, if target file was 3000 bytes long and you want to fetch using three thread:

    • Thread 1: fetches bytes 1 to 1000
    • Thread 2: fetches bytes 1001 to 2000
    • Thread 3: fetches bytes 2001 to 3000

    You would pre-allocate an empty file of the original size, and write back to the respective positions within the file.

提交回复
热议问题