找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 489|回复: 0

[求助] 将多线程改写成多协程

1

主题

1

帖子

1

积分

贫民

积分
1
awdwaasd 发表于 2022-12-7 13:20:44 | 显示全部楼层 |阅读模式
请问一下,有没有哪位大佬知道怎么把下面的代码改写成多协程版本的,这个函数主要是用于读取图片数据
  1. import os
  2. import time
  3. from concurrent.futures import ThreadPoolExecutor

  4. from PIL import Image


  5. def read_image(dir_path):
  6.     files = os.listdir(dir_path)
  7.     files_path = [os.path.join(dir_path, file) for file in files]
  8.     with ThreadPoolExecutor() as executor:
  9.         images = executor.map(Image.open, files_path)
  10.     return list(images)
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表