def _multi_thread_download(url, file_name, file_size, thread_count):
import threading
fp = open(file_name, "wb")
fp.truncate(file_size)
fp.close()
part = file_size // thread_count
for i in range(thread_count):
start = part * i
if i == thread_count - 1:
end = file_size
else:
end = start + part
t = threading.Thread(target=_downloader, kwargs={'start': start, 'end': end, 'url': url, 'filename': file_name})
t.setDaemon(True)
t.start()
main_thread = threading.current_thread()
for t in threading.enumerate():
if t is main_thread:
continue
t.join()
return file_name
评论列表
文章目录