我有一个带有3个参数的tasklet,一个带有id和title的字典,一个用户密钥和一个已经存在于数据库中的记录列表.在for循环中调用函数defer_fetch N次.
@ndb.tasklet
def defer_fetch(data, user_key, already_inserted):
if data['_id'] not in already_inserted:
document_key = yield Document.fetch_or_create(data)
yield defer_fetch_document(user_key, document_key)
else:
document_key = alread_inserted[data['_id']]
raise ndb.Return(document_key)
@ndb.tasklet
def defer_fetch_document(user_key, document_key):
deferred.defer(process_document, user_key, document_key, _queue="process-documents")
raise ndb.Return(True)
Run Code Online (Sandbox Code Playgroud)
document.fetch_or_create的代码在defer_fetch的所有调用之间并行执行,但调用fetch_document不是,如附件所示

如何使defer_fetch_document也并行运行?
我的困惑是为什么我需要包括“传统”云存储角色。我更喜欢避免说“遗留”的东西,因为听起来它们会在这些天中被弃用。我做错了吗?
这是我的情况:
我正在使用 appengine 项目中的服务帐户访问另一个项目中云存储中的文件。我正在使用 Google Python 客户端访问数据。
我分配了角色:
Storage Object Creator
Storage Object Viewer
Run Code Online (Sandbox Code Playgroud)
但是当我尝试访问文件时出现错误:
<service account> does not have storage.buckets.get access
Run Code Online (Sandbox Code Playgroud)
只有在我添加了“遗留角色”之后,它才最终可以访问:
Storage legacy bucket writer
Storage legacy bucket reader
Run Code Online (Sandbox Code Playgroud)
这是代码:
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
print('Blob {} downloaded to {}.'.format(
source_blob_name,
destination_file_name))
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name, …Run Code Online (Sandbox Code Playgroud)