【发布时间】:2021-03-30 20:24:03
【问题描述】:
我有以下示例代码。这是作为 Yandex.Functions 运行的(几乎等于 AWS 函数)。
def handler(event, context):
# some long processing is here
text = result_of_long_processing()
return {
'response': {
'text': text
},
}
我应该按以下方式修改代码:
- 如果
long processing的时间少于3秒,那么应该返回这个处理的结果 - 如果超过 3 秒,则应返回一些标准文本(如
wait more)并继续处理。
我怎样才能实现它?
【问题讨论】:
-
尝试使用 time 模块,您可以通过设置 start = time.time() 和稍后 end = time.time() 并减去这两个来计算代码中 2 个点之间的时间。
标签: python amazon-web-services python-3.7 yandexcloud