为什么python进度条在下载完成后启动

为什么python进度条在下载完成后启动,python,python-3.x,download,progress-bar,Python,Python 3.x,Download,Progress Bar,我在python程序中添加了一个进度条, 但它会在下载完成后开始 我下载了一个大文件,过了很长时间才开始。 当进度条从0%开始时,文件已下载 我能为它做些什么? 我需要它显示在下载的开始 完整代码: 条形码: def download(url, fname): resp = requests.get(url, stream=True) total = float(content_length) with open(fname, 'wb') as file, tqdm(

我在python程序中添加了一个进度条, 但它会在下载完成后开始

我下载了一个大文件,过了很长时间才开始。 当进度条从0%开始时,文件已下载

我能为它做些什么? 我需要它显示在下载的开始

完整代码:

条形码:

def download(url, fname):
    resp = requests.get(url, stream=True)
    total = float(content_length)
    with open(fname, 'wb') as file, tqdm(
            desc=fname,
            total=total,
            unit='iB',
            unit_scale=True,
            unit_divisor=1024,
    ) as bar:
        for data in resp.iter_content(chunk_size=1024):
            size = file.write(data)
            bar.update(size)

download(d_link,songname)    

可能尝试在另一个线程中运行它,因为我认为它会在之后执行
    def progres_(self, streams, chunk, bytes_remaining):
        percentage = (float(abs(bytes_remaining - self.size_inBytes) / self.size_inBytes)) * float(100)
        self.progres_bar["value"] = percentage
        self.progres_bar.update()
        self.lbl_percentage.config(text=f" Downloading: {str(round(percentage, 2))}%")
        if round(percentage, 2) == 100:
            self.lbl_message.config(text="Download Completed", fg="green")
            self.btn_download.config(state=tk.DISABLED)