异步在龙卷风中如何工作? [英] How does async work in Tornado?

查看:64
本文介绍了异步在龙卷风中如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tornado文档中的所有示例都显示了如何使用Tornado异步发出更多HTTP请求。

All examples in the Tornado documents show how we can make further HTTP requests asynchronously using Tornado.

http_client = httpclient.AsyncHTTPClient()
http_client.fetch("http://www.google.com/", handle_request)

虽然我想确保龙卷风不等待数据库的响应(获取沙发床命令)随后发送。

While I want to ensure that my tornado doesn't wait for response from database (get command of couchbase) to send next.

检查我的其他错误以了解为什么我要异步调用沙发床。

Check my other bug to understand why I want async call to couchbase.

推荐答案

据我所知,Couchbase驱动程序是不是异步驱动程序,因此无法正常工作。使数据库调用同步并尽可能快地对其进行优化。

As far as I know Couchbase driver is not an async driver so this wont work. Make the db call synchronous and optimize it to be as fast as possible.

(吓人的)替代方法是使用cubbase的驱动程序并使用gevent之类的补丁对其进行修补,以创建您的自己的异步驱动程序。我不建议这样做。如果您真的想走这条路,请看看这个人对电机-他使mongo驱动程序异步。

The (scary) alternative is to take couchbase's driver and patch it with something like gevent to create your own async driver. I do not recommend doing this. If you really want to go down this route look at what this guy did with Motor - He made the mongo driver async.

这篇关于异步在龙卷风中如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆