- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 POST
方法,它调用一些 tasklet。这些 tasklet 确实有 yield ,我的代码中确实有一些 x.put_async()
。所以我不希望它在所有异步内容完成之前返回。所以我用 @ndb.tasklet
修饰了我所有的 tasklet,它们只是一些小函数。此外,在我的 POST
方法之上,我有:
@ndb.toplevel
def post(self):
但是,在 documentation它指出:
But if a handler method uses yield, that method still needs to be wrapped in another decorator, @ndb.synctasklet; otherwise, it will stop executing at the yield and not finish.
我的方法确实有收获。它已经包装在@ndb.tasklet 中。我是将其替换为 @ndb.synctasklet 还是两者都使用(如果是,我将如何同时使用两者)?
另请参阅 this thread这有一定的相关性。我也注意到一个问题,即我的请求将在没有任何输出的情况下返回,但无法重现。它每 15 分钟左右持续使用一次。我只有 app = ndb.toplevel(webapp2.WSGIApplication([..])
,但现在我已经将 @ndb.toplevel
添加到主 POST
方法,但问题仍然存在。
我是否应该将 @ndb.tasklet
放在也只有 put_async()
的方法之上? (为了安全起见,我是否应该将它放在每个方法之上?这样做有什么缺点?)
最佳答案
关于处理程序和使用@ndb.toplevel 和@ndb.synctasklet:我的理解是,您需要在处理程序上同时使用 @ndb.synctasklet 和 @ndb.toplevel。所有子任务只需要 @ndb.tasklet 装饰器。例如
class Foo(ndb.Model):
name = ndb.StringProperty()
@ndb.tasklet
def my_async(self):
....
#do something else that yields
raise ndb.Return("some result")
@ndb.toplevel
@ndb.synctasklet
def post(self):
foo = Foo(name="baz")
yield foo.put_async()
yield foo.my_async()
....
但是。看着 source ,看起来 @ndb.toplevel 实际上是一个 synctasklet:
def toplevel(func):
"""A sync tasklet that sets a fresh default Context.
Use this for toplevel view functions such as
webapp.RequestHandler.get() or Django view functions.
"""
在处理程序中使用 yields 运行一个小测试并用 @ndb.toplevel 装饰似乎仍然有效,而且您似乎可以从处理程序中删除 @ndb.synctasklet。
关于是否应该在调用 put_async() 的方法中包含 @ndb.tasklet:如果你没有在 put_async() 上产生,那么你不需要在周围的方法中包含 @ndb.tasklet(@ndb.toplevel 将处理从 put_async() 获取结果)
关于python - 在 Google App Engine 中使用 @ndb.tasklet 或 @ndb.synctasklet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12256093/
当tasklet在执行过程中触发硬件中断时,tasklet的状态会发生什么变化? 最佳答案 Tasklet 是下半部分。它们在软中断上下文中运行,而不是在硬件中断上下文中运行。所以硬件中断总是启用的。
我有一个要求,其中一个 tasklet 将目录中的所有文件存储在一个数组列表中。列表的大小存储在作业执行上下文中。稍后在另一个步骤中从另一个 tasklet 访问此计数。它是如何做到这一点的。我试图存
我有一个 tasklet 将一些信息设置到我的 JobContext 中,另一个 tasklet 检查一些东西以了解我是否可以执行批处理中的后续步骤。 如果我在我的工作流程中使用两个不同的步骤,这两个
在处理tasklet时,中断是否被禁用,因为它们应该在中断上下文中运行。如果在处理tasklet时中断,那么将它们称为下半部分机制有什么意义,因为它与禁用中断的顶部情况相同。或者,tasklet 是否
我想构建一个内核模块,它会在按下 f5 键时运行一个 tasklet。 我知道如何初始化一个 tasklet,但是如何在我的模块中获取事件?如何使用 request_irq 确定是否按下了 f5? 最
在我的大学里,我正在从事一个涉及一些内核编程的项目。其中一部分是可加载内核模块,它为某个给定的中断注册中断处理程序。 现在我已经共享了中断处理程序和 tasklet 使用的数据结构,我想知道我是否可以
我知道 Tasklets 是延迟中断处理程序,它们在中断上下文中执行,除了它们具有最高优先级(当然高于用户进程)。 但是,如果我们有多个 Tasklets 有很多工作要做,这些 Tasklets 是如
我正在使用 Google App Engine SDK 1.7.3 和 NDB 来访问数据存储区。 我应该如何从事务性tasklet 中运行非事务性tasklet? 我首先想到的是以下内容: @ndb
我有一个中断处理程序,它按如下方式安排一个 tasklet(伪代码)- struct tasklet_struct mytasklet; void my_tasklet_function(unsign
你好,我正在尝试使用 call_usermodehelper_exec 从 tasklet 运行用户空间进程,该进程是在带有 Allwinner SOC 的 ARM 板(来自 Olimex)的内核模块
新的 Mono Continuations/Tasklet 框架的主要性能开销(gc/堆栈复制...)是什么? 与 Lua Coroutine 和 stackless python 等其他框架相比,这
来自 documentation : An NDB tasklet is a piece of code that might run concurrently with other code. If
我正在尝试将参数从 tasklet 安全地传递到同一作业中的步骤。 我的工作包括 3 个 tasklet(step1,step2,step3) 一个接一个,最后一个 step4(processor,r
我正在使用 GAE,但我意识到当我尝试启动 .py 文件时出现此错误。我能做些什么?谢谢 python3 test.py runserver Traceback (most recent call
如何获取执行 tasklet 函数的任务的 pid。 current->pid 不会工作,因为 tasklet 在中断上下文中运行。当前很可能指的是被中断的任务。 最佳答案 从您需要 pid 的任务中
据说 Softirqs/tasklets 在中断上下文中执行我有以下关于中断上下文底部的问题。 Q1)如果我们尝试让 tasklet 进入休眠状态(中断上下文下半部分)会发生什么(考虑 tasklet
我正在尝试掌握 NDB 引入的异步操作,我想使用 @ndb.tasklet 来异步我的一些工作。 简单的例子是在重写的 get_or_insert_async 中生成 string_id 这是处理事情
GvRs App Engine ndb Library以及monocle并且——据我所知——现代 Javascript 使用生成器使异步代码看起来像阻塞代码。 事物用@ndb.tasklet装饰。他们
我是一个 Linux 设备驱动新手,想知道 tasklet 和 workqueue 之间的确切区别。我有以下疑问: Which kernel stack do interrupts, tasklet
我是一名优秀的程序员,十分优秀!