如何在 Pyramid 中响应完成后执行方法?
将 Pyramid 与 Akhet 结合使用,如何在响应返回给客户端后执行方法?我相信这是通过 Pylons 中的 __after__ 方法完成的。我正在尝试执行数据库查询,但不希望它阻止请求响应。
Using Pyramid with Akhet, how do I execute a method after a response has been returned to the client? I believe this was done with the __after__
method in Pylons. I'm trying to execute a DB query and don't want it to block the request response.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用响应回调 针对您的情况。
在 Michael Merickel 的评论后编辑:响应回调会阻止添加的请求,但您不必担心该回调会阻止其他请求,因为每个请求都在不同的线程中运行。如果您仍然不需要使用回调来阻止请求,您可以生成不同的线程或进程(如果您负担得起)或查看消息队列系统,如下面的评论中所述。
You can use a response callback for your case.
EDITED after Michael Merickel's comment: The response callback blocks the request to which is added, but you shouldn't worry about that callback blocking other requests since each request runs in a different thread. If you still need not to block the request with the callback, you can spawn a different thread or process (if you can afford it) or look into message queuing systems as mentioned in the comment below.