我正在学习Python 3中的线程和多处理。我尝试了一个与ThreadPoolExecutor一起使用的简单Programm,但是当我更改为ProcessPoolExecutor时,它没有执行任何给定的代码。
from PIL import Image
from PIL import ImageFilter
import os
directory = r'C:\Users\admin\OneDrive\Pictures\My Photos'
imgs_file = []
for img_file in os.listdir(directory):
if (img_file.endswith(".JPG") or img_file.endswith(".jpg")):
imgs_file.append(img_file)
def image_filter(image_file):
img = Image.open(image_file)
img= img.filter(ImageFilter.GaussianBlur(radius = 9))
img.save(f'Converted {image_file}')
import concurrent.futures
with concurrent.futures.ProcessPoolExecutor() as p:
p.map(image_filter, imgs_file)