python - 基于python中的计数的计时器
问题描述
我正在尝试将我的查询值传递给外部 API,但由于 API 存在限制问题,我每 5 分钟只能进行 500 次调用,并且需要 10 分钟的冷却时间。所以我正在尝试,我添加了一个计数增量方法,如果计数超过 400 则休眠 2 分钟,我知道错误在我的代码中,但我不知道如何编写函数。
for info in contact:
id = info[0]
name = info[1]
print(id)
count += 1
print(count)
if count > 400:
print('11111111')
time.sleep(120)
print ("count crossed 400....")
print ("sleep for 2 minutes")
else:
logging.info(count)
print(name)
try:
...
所以这将检查计数,如果计数超过 400,它将为每个其他呼叫休眠 2 分钟,直到完成。我试图以这样一种方式做到这一点,即每 400 个调用睡眠 2 分钟,如何在 python 中编写它。好心指导
解决方案
for info in contact:
id = info[0]
name = info[1]
print(id)
count += 1
print(count)
if count > 400:
print('11111111')
time.sleep(120)
count = 0
print ("count crossed 400....")
print ("sleep for 2 minutes")
else:
logging.info(count)
print(name)
添加行 : count = 0
,它将变量重置count
为 0if count > 400
推荐阅读
- flutter - 未为类型“Iterable”定义运算符“[]”
'。尝试定义运算符 '[]'.dartundefined_operator - vue.js - 为什么 '@drop' 事件在 vue 中对我不起作用?
- r - 根据 2 个不同的条件过滤多个字符串列 - 关于“grepl”和“starts_with”的问题
- javascript - 我可以在 React 中有组件接口吗?
- android - 如何在整个颤振项目中使用 json 对象之一?
- cordova - 离子底部导航栏(Android 10)样式
- python-3.x - Python 3 中带有 tkinter 和类的 Gif 动画
- mysql - 无法在 SSIS 中将 CSV 文件导入 MySQL
- iterm2 - 提示左侧多余的蓝色字形
- python-3.x - 使用 Python 解析的 HTML 网页与实际页面不同