解决句柄占用问题。

This commit is contained in:
liuwei
2025-05-26 10:08:29 +08:00
parent 9731589d6d
commit 3832997ac5
3 changed files with 58 additions and 61 deletions

View File

@@ -150,12 +150,11 @@ def download_image(img_url, folder_path, img_index, max_retries=3):
time.sleep(2 * (attempt + 1))
continue
img = Image.open(BytesIO(response.content)).convert('RGB')
img_name = f"{img_index:03d}.jpg"
img_path = os.path.join(folder_path, img_name)
img.save(img_path, 'JPEG', quality=95)
logger.info(f"已下载并转换为JPG: {img_path}")
with Image.open(BytesIO(response.content)).convert('RGB') as img:
img_name = f"{img_index:03d}.jpg"
img_path = os.path.join(folder_path, img_name)
img.save(img_path, 'JPEG', quality=95)
logger.info(f"已下载并转换为JPG: {img_path}")
return True
except Exception as e: