You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pyrogram设置4个worker仍串行下载头像问题求助

Pyrogram并行下载用户头像异常问题
  • 配置Pyrogram客户端为4个worker,意图同时下载多个用户头像
  • 程序执行时会提前创建所有下载临时文件,但实际下载操作是逐个进行,未实现并行
  • 已确认Python异步并行逻辑无问题,问题出在Pyrogram库本身
  • 该问题存在官方相关Issue

代码示例

photos = await generator_to_list2(client.get_chat_photos(chat_member.user.id))
photos: list[pyrogram.types.Photo]
tasks = []
for index, photo in enumerate(photos):
    tasks.append(asyncio.create_task(
        client.download_media(
            message=photo.file_id,
            file_name=f'{path}/files/photos/{index}.jpg'
        )
    ))

await asyncio.gather(*tasks)
print('fully done!')

内容的提问来源于stack exchange,提问作者EBRAHIM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 11:32:33