これから続ける:https://codereview.stackexchange.com/questions/
リストにバイト数のデータを保持するとコストがかかり、システムのパフォーマンスが低下する可能性があることを発見したので、そのスレッドの範囲が完了したらすぐにデータをディスクに書き込む方が良いと思います。キューで終了する次のスレッドからの範囲のチャンクを書き込みます..
def main(url=None, splitBy=6):
start_time = time.time()
if not url:
print "Please Enter some url to begin download."
return
fileName = url.split('/')[-1]
sizeInBytes = requests.head(url, headers={'Accept-Encoding': 'identity'}).headers.get('content-length', None)
print "%s bytes to download." % sizeInBytes
if not sizeInBytes:
print "Size cannot be determined."
return
threads = []
lock = threading.Lock()
byteRanges = buildRange(int(sizeInBytes), splitBy)
for idx in range(splitBy):
bufTh = SplitBufferThread(url, byteRanges[idx])
bufTh.daemon = True
bufTh.start()
threads.append(bufTh)
print "--- %s seconds ---" % str(time.time() - start_time)
with open(fileName, 'w+') as fh:
for t in threads:
t.join()
fh.write(t.data)
fh.flush()
print "Finished Writing file %s" % fileName
if __name__ == '__main__':
main(url)
では、バイトの範囲がスレッドによって完了するとすぐにファイルチャンクをディスクに書き込む方法は?