在ndb Tasklet中使用images.get_serving_url_async()是否安全? [英] Is it safe to use images.get_serving_url_async() inside a ndb tasklet?

查看:60
本文介绍了在ndb Tasklet中使用images.get_serving_url_async()是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NDB tasklet和yield是执行异步/并行代码的好方法.但是,从文档中还不清楚这种机制是否可以安全地与非ndb异步功能(例如images.get_serving_url_async())一起使用.

NDB tasklets and yield are a great way to do async/parallel code. However, it is not quite clear from the documentation if this mecanism can be safely used with non-ndb async functions such as images.get_serving_url_async().

NDB异步操作文档页面很小关于使用NDB上下文自身版本的urlfetch_async()的部分,在此处声明(强调我的意思):

The NDB Asynchronous Operation documentation page has a very tiny section about using the NDB context's own version of urlfetch_async(), where it is stated (emphasis mine):

URL Fetch服务具有其自己的异步请求API. 这很好,但与NDB Tasklet结合使用并不总是很容易.

我不太清楚为什么它并不总是很容易与NDB tasklet一起使用",这让我想知道同一条语句是否适用于images.get_serving_url_async().

It is not quite clear to me why it is "not always easy to use with NDB tasklets", and this makes me wonder if the same statement applies to images.get_serving_url_async().

所以我的问题是:如果这样做我会遇到麻烦吗?

So my question is: will I get into trouble if I do this?

@ndb.tasklet
def foo():
    url = yield images.get_serving_url_async(image_key)

推荐答案

很好.收益将等待RPC,并允许其他Tasklet在等待时运行.关于urlfetch的评论只是关于它笨拙的API.

It is fine. The yield will wait for the RPC and allow other tasklets to run while waiting. The comment about urlfetch was just about its clumsy API.

这篇关于在ndb Tasklet中使用images.get_serving_url_async()是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆