Python 如何执行并发aws重新确认请求
我正在复制一项有33000张图片的研究,我正在使用aws Rekognion来标记这些图片。然而,我似乎无法获得正确的并发性。第一次在Python中使用线程,所以我的无知可能是问题所在 单线程应用程序可以工作,但我的并发尝试只写空标签。 我的代码有问题吗 下面是正在工作的单线程代码,速度很慢,需要花费很长时间。 我在github上设置了一个示例图像集 以及输出为空的多线程代码Python 如何执行并发aws重新确认请求,python,multithreading,amazon-web-services,concurrency,Python,Multithreading,Amazon Web Services,Concurrency,我正在复制一项有33000张图片的研究,我正在使用aws Rekognion来标记这些图片。然而,我似乎无法获得正确的并发性。第一次在Python中使用线程,所以我的无知可能是问题所在 单线程应用程序可以工作,但我的并发尝试只写空标签。 我的代码有问题吗 下面是正在工作的单线程代码,速度很慢,需要花费很长时间。 我在github上设置了一个示例图像集 以及输出为空的多线程代码 import boto3 import concurrent.futures import threading imp
import boto3
import concurrent.futures
import threading
import time
import os
client = boto3.client('rekognition')
def download_labels(image_url):
image_url_path = "small_images/" + image_url
with open(image_url_path, "rb") as image:
f = image.read()
b = bytearray(f)
response = client.detect_faces(
Image={
'Bytes': b
},
Attributes=[
'ALL'
]
)
filename = "Labels/" + image_url + ".json"
with open(filename, 'w') as json_file:
json.dump(response, json_file)
def download_all(images):
with concurrent.futures.ThreadPoolExecutor(max_workers=30) as executor:
executor.map(download_labels, images)
if __name__ == "__main__":
image_list = os.listdir("Images/")
start_time = time.time()
download_all(image_list)
duration = time.time() - start_time
print(f"Downloaded {len(image_list)} in {duration} seconds")
import boto3
import concurrent.futures
import threading
import time
import os
client = boto3.client('rekognition')
def download_labels(image_url):
image_url_path = "small_images/" + image_url
with open(image_url_path, "rb") as image:
f = image.read()
b = bytearray(f)
response = client.detect_faces(
Image={
'Bytes': b
},
Attributes=[
'ALL'
]
)
filename = "Labels/" + image_url + ".json"
with open(filename, 'w') as json_file:
json.dump(response, json_file)
def download_all(images):
with concurrent.futures.ThreadPoolExecutor(max_workers=30) as executor:
executor.map(download_labels, images)
if __name__ == "__main__":
image_list = os.listdir("Images/")
start_time = time.time()
download_all(image_list)
duration = time.time() - start_time
print(f"Downloaded {len(image_list)} in {duration} seconds")