2017-07-17 30 views
1

我试着分析与AWS Rekognition进行API调用并行

在一个循环的主要功能多张图片:

with open("Test/frame%d.jpg" % count, "rb") as image: 
    for face in RekognitionClass.detect_faces(image): 
    =>Process result and write in DB 

Rekognition类:

def detect_faces(image, attributes=['ALL'], region="eu-west-1"): 
rekognition = boto3.client("rekognition", region) 
response = rekognition.detect_faces(Image={'Bytes': image.read()}, Attributes=attributes) 
return response['FaceDetails'] 

但一个API调用约需至少2秒,如果可能,我想多打几个电话

回答

0

我能够使用python多线程进行更多的并行函数调用,并且每次都在新线程中启动detect_faces函数。 它与会话使用boto3客户端的多线程

主要是很重要的:

p = Process(target=RekognitionClass.detect_process_faces, args= (count,)) 
    p.start() 
在RekognitionClass

def detect_faces(count, attributes=['ALL'], region="eu-west-1"): 
session = boto3.session.Session() 
rekognition = session.client("rekognition", region)...