6
NDB tasklets和yield
是做異步/並行代碼的好方法。但是,從文檔中不太清楚這種機制是否可以安全地用於非ndb異步函數,如images.get_serving_url_async()
。在ndb tasklet中使用images.get_serving_url_async()是否安全?
的NDB Asynchronous Operation documentation page有大約使用的urlfetch_async()
,其中規定(重點煤礦)的NDB上下文的自己的版本一個很小的部分:
網址提取服務都有自己的異步請求的API。 這很好,但並不總是很容易與NDB小程序一起使用。
它不是很清楚爲什麼它「並不總是很容易與NDB tasklets一起使用」,這讓我懷疑同樣的說法是否適用於images.get_serving_url_async()
。
所以我的問題是:如果我這樣做,我會陷入困境嗎?
@ndb.tasklet
def foo():
url = yield images.get_serving_url_async(image_key)
根據這個被拒絕的特性請求,它看起來像我可以'屈服'由'get_serving_url_async()'返回的RPC對象。 http://code.google.com/p/appengine-ndb-experiment/issues/detail?id=151 – 2013-02-12 18:36:01