我在几个文件中迭代了几个 JSON 对象。我将使用来自此类 JSON 对象的一些参数进行 Twitter API 调用。
但是,Twitter API 有一个限制,我每 15 分钟不能超过180 次调用。
API 调用是使用库执行的,让我们调用进行调用api
的对象。
拥有一个,sleep
每次达到极限时我都会使用 a ,等待后我会继续。但是,由于我可以为不同的 Twitter 应用程序使用多个api
对象,因此我想为它们分配调用语句并在必要时让它们等待,但api
如果没有必要或整个执行过程中不停止另一个对象。
假设我有:
api1, api2, api3, api4, api5 ... api10
这是我迭代并到达 API 调用点的代码:
for f in os.listdir('tweets'):
#print f
with open('tweets/'+f,'r', buffering=1) as jsonQuery:
twitterJSON = json.load(jsonQuery)
for category in twitterJSON:
for trend in twitterJSON[category]:
j = 0
for t in twitterJSON[category][trend]:
self.dist=[]
values = []
# I'd make the call here for
# any of the api variables which gets its turn.
如何在循环和循环中将任务线程化到任何一个api
?