Skip to content

Commit

Permalink
修改了timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
HViktorTsoi committed Oct 10, 2017
1 parent 79edf96 commit 1c97435
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Downloader:
downloader.start()
"""

def __init__(self, threads_num=20, chunk_size=1024 * 128, timeout=60):
def __init__(self, threads_num=20, chunk_size=1024 * 128, timeout=0):
"""初始化
:param threads_num=20: 下载线程数
Expand All @@ -41,7 +41,7 @@ def __init__(self, threads_num=20, chunk_size=1024 * 128, timeout=60):
"""
self.threads_num = threads_num
self.chunk_size = chunk_size
self.timeout = timeout
self.timeout = timeout if timeout != 0 else threads_num # 超时时间正比于线程数

self.__content_size = 0
self.__file_lock = threading.Lock()
Expand Down Expand Up @@ -119,7 +119,6 @@ def __download(self, url, file, page):
# 数据流每向前流动一次,将文件指针同时前移
page["start_pos"] += len(data)
self.__threads_status[thread_name]["page"] = page
print("{}向logger队列传输数据".format(thread_name))
self.__msg_queue.put(self.__threads_status)

except requests.RequestException as exception:
Expand Down Expand Up @@ -185,11 +184,11 @@ def __log_metainfo(self):
self.__threads_status["target_file"],
self.__threads_status["content_size"] / 1024
))
print("下载中......")

def __log_threadinfo(self):
"""输出各线程下载状态信息
"""
print("下载中......")
downloaded_size = 0
for thread_name, thread_status in self.__threads_status.items():
if thread_name not in ("url", "target_file", "content_size"):
Expand Down Expand Up @@ -236,9 +235,9 @@ def run(self):

if __name__ == '__main__':
DOWNLOADER = Downloader(
threads_num=100
threads_num=10
)
DOWNLOADER.start(
url="http://fjyd.sc.chinaz.com/Files/DownLoad/pic9/201709/bpic3616.rar",
target_file="/tmp/tmp.rar",
url="http://download.virtualbox.org/virtualbox/5.1.28/virtualbox-5.1_5.1.28-117968~Ubuntu~trusty_amd64.deb",
target_file="/tmp/tmp.mp4",
)

0 comments on commit 1c97435

Please sign in to comment.