0
我正在編寫這個程序,它使用線程同時下載多個文件並報告屏幕上每個文件的進度。 我正在使用一個不同的線程來下載每個文件。這是沒有問題的:Python Threading:多行進度報告
for file_url, filename in zip(file_urls, filenames):
th = Thread(target=download_file, args=(file_url, filename))
threads.append(th)
th.start()
for thread in threads:
thread.join()
的問題是我不知道,反正我可以打印屏幕上的每個文件的進度報告,這將是這樣的:
"Downloading 'example1.zip': 54366 bytes of 2240799 70.7%"
"Downloading 'example2.zip': 31712 bytes of 1924639 64.7%"
"Downloading 'example3.zip': 21712 bytes of 3224979 34.7%"
以下片段是單行進度報告:
def chunk_report(bytes_so_far, total_size, filename):
percent = float(bytes_so_far)/total_size
percent = round(percent * 100, 2)
print "Downloading '{0}': {1} of {2} {3:3.2g}% \r".format(filename,
bytes_so_far, total_size, percent),
和輸出應該是這樣的:
"Downloading 'example2.zip': 31712 bytes of 1924639 64.7%"
每次線程調用此函數時,它都會更新線程正在下載的文件的屏幕。
所以,問題是如何打印多行進度報告,就像我上面在python中說明的那樣?
在此先感謝。