gpt4 book ai didi

google-app-engine - ndb async 是否保证在应用程序请求完成后执行?

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:48 24 4
gpt4 key购买 nike

我正在使用 ndb 编写一个分析模型,该模型记录每个应用程序请求的一些数据。每个请求通过 ndb.put_async 调用一个 ndb 请求来记录数据,而客户端不关心结果。本质上,我不希望应用程序请求等待保存统计数据以进行分析。

然而,我对官方文档的解释感到困惑。如果应用程序请求在 ndb 请求完成之前完成,是否仍能保证 ndb 请求完成?文档表明

if the request handler exists too early, the put might never happen

在什么条件下会发生这种情况?这是否意味着无论用户是否关心结果,都需要调用 future.get_result 以确保执行 ndb 请求?

原始文档 ( https://developers.google.com/appengine/docs/python/ndb/async ) 说:

In this example, it's a little silly to call future.get_result: the application never uses the result from NDB. That code is just in there to make sure that the request handler doesn't exit before the NDB put finishes; if the request handler exits too early, the put might never happen. As a convenience, you can decorate the request handler with @ndb.toplevel. This tells the handler not to exit until its asynchronous requests have finished. This in turn lets you send off the request and not worry about the result.

最佳答案

If an application request has finished before the ndb request finishes, would the ndb request still be guaranteed to finish?

没有。

Does this mean that regardless of whether a user care about the result, future.get_result needs to be called anyway just to make sure the ndb request is performed?

基本上是的,但是为了方便起见,您可以使用 ndb.toplevel 装饰器,这样您就不必显式地等待结果。也就是说,我认为这不是您想要的。

可能 taskqueue是你想要的。请检查一下。

关于google-app-engine - ndb async 是否保证在应用程序请求完成后执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11621313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com