1

我正在使用谷歌的距离矩阵 API,并希望在 10 秒内达到 1000 个请求的速率限制,而不必使用矩阵组件,但只是更高的限制能力(方向 API 每秒有 10 个 -> 这实际上每秒有 100 个)。

编辑:

我的主要目标是能够准确控制我每秒填充多少个请求(例如在 10 秒内完成 800 个请求,或者在几秒内完成 1000 个请求),理想情况下我会使用这种伪代码,但我不确定:

pool = Pool()  # Initialize a pool of max processes
start_time = time.time()
counter = 0
for one_url in URL_LIST:
    counter += 1
    # Once sent 1000 requests
    if counter = 1000:
        # If elapsed less than 10 seconds
        if time.time() - start_time < 10 seconds:
            # Wait until we hit 10 seconds
            time.sleep(time.time() - start_time)  
        else:
            #Taking more than 10 seconds
            pass
        #Reset counter and timer
        start_time = time.time()  
        counter = 0   
    RESULTS_OUT = pool.map(GeocodeHandler, one_url) 
pool.close()  # This means that no more tasks will be added to the pool
pool.join()  # This blocks the program till function is run on all the items
4

0 回答 0