代表一个可等待操作对象的基本类型。借助可等待对象,开发者可以以同步或异步面向对象编程的方式等待一个异步操作真正地完成,例如同步等待一个或多个无服务器云函数资源创建完成。
from tencent.cloud.core import errors
from tencent.cloud.core import waitable
from tencent.cloud.serverless import functions
def main():
client: functions.Client = functions.fetch_client()
create_operation: waitable.Waitable = client.create_layer(
region_id = 'ap-shanghai',
layer_name = 'default',
layer_description = 'default layer',
layer_content = functions.LayerContent().use_local_zip_archive(
local_file_path = './layer.zip'
),
layer_runtimes = [
functions.FunctionRuntime.Python
],
layer_license = 'default license'
)
try:
layer_version: int = create_operation.wait_for_done(
max_wait_seconds = 15
)
except TimeoutError:
print('error: max time limit exceeded when creating layer resource')
return
print('info: layer version = {LAYER_VERSION}'.format(
LAYER_VERSION = layer_version
))
if __name__ == '__main__':
main()
Tencent Cloud SDK for Python