Is it safe to use images.get_serving_url_async() inside a ndb tasklet?

大憨熊 提交于 2019-12-06 01:31:31

问题


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().

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):

The URL Fetch service has its own asynchronous request API. It's fine, but not always easy to use with NDB tasklets.

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)

回答1:


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.



来源:https://stackoverflow.com/questions/14837590/is-it-safe-to-use-images-get-serving-url-async-inside-a-ndb-tasklet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!