import time
with open('downloadingfile.mp4', 'rb') as f:
total_read = 0
while total_read < file_size:
data = f.read()
if data:
total_read += len(data)
# process this chunk
time.sleep(1)
def Handel_Progress(self , blocknum , blocksize , totalsize):
## calculate the progress
readed_data = blocknum * blocksize
if totalsize > 0 :
download_percentage = readed_data * 100 / totalsize
self.setValue(download_percentage)
processEvents()# before process even put the name of the application or if you are using python without make to it GUI I don't know what to do
如果知道预期的文件大小,请在循环中调用
read()
,直到达到该大小你必须首先知道,有一种先进的线程方式,大公司使用这种方式,但在这里我要展示一种线程方式,但它不是先进的尝试这段代码我不知道它是否会工作我是编程新手
相关问题 更多 >
编程相关推荐