python - 如何在等待 API 返回值时等待并显示进度信息
问题描述
我有下面的代码,我正在等待方法调用返回响应。此响应可能需要 10 到 15 秒以上。
我需要在用户等待方法返回响应时显示进度消息。我的 while 条件似乎没有显示进度条。
response = my_api.execute("get some data")
# There is a 10-15 minute delay here...
i = 0
while response is None:
sys.stdout.write('\r')
sys.stdout.write("Fetching MO attribute [%-20s] %d%%" % ('=' * i, 5 * i))
sys.stdout.flush()
sleep(0.25)
i += 1
if response.get_output() != "1 instance(s)":
raise MyError('Could not fetch data. )
for line in response.get_output():
# Do the actual processing
解决方案
推荐阅读
- react-native - react-navigation BottomTabNavigator 在生产中被切断
- python - KeyError:“[Int64Index dtype='int64', length=9313)] 都不在 [columns] 中”
- typescript - 使用约束创建映射类型的对象
- javascript - javascript如何分配参考值?
- javascript - 合并和组合具有相同日期的数组项
- r - 通过删除括号内的所有文本
- android - 保存视频前的ffmpeg实时预览
- python - IndexError:运行 mask-rcnn 时列表索引超出范围?
- android - InputManager 自动从列表中删除无线控制器
- python - 如何修复 [Errno 20] 不是目录:'/app/myProjectManager/settings.py/staticfiles/staticfiles.json' Django