我有以下代码,从Amazon的API中请求一些内容:
params = {'Operation': 'GetRequesterStatistic', 'Statistic': 'NumberHITsAssignable', 'TimePeriod': 'LifeToDate'}
response = self.conn.make_request(action=None, params=params, path='/', verb='GET')
data['ActiveHITs'] = self.conn._process_response(response).LongValue
params = {'Operation': 'GetRequesterStatistic', 'Statistic': 'NumberAssignmentsPending', 'TimePeriod': 'LifeToDate'}
response = self.conn.make_request(action=None, params=params, path='/', verb='GET')
data['PendingAssignments'] = self.conn._process_response(response).LongValue
每一个请求都需要1s的时间等待Amazon返回数据。我如何同时运行这两个程序,这样(理想情况下)只需要1秒,而不是2秒?在
您可以使用^{} 来并行化请求:
这样可以并行处理任何给定数量的请求。默认情况下,每个核心创建一个worker,您可以通过向
Pool
传递一个参数来更改该数字。在相关问题 更多 >
编程相关推荐