我尝试使用Corduroy来使用pythonTornado Web Server异步地与CouchDB通信。在
下面的代码来自Corduroy guide,有一些改动。在
import tornado.web
from corduroy import Database, NotFound, relax
people_db = Database('people')
class RelaxedHello(tornado.web.RequestHandler):
@relax
def get(self, user_id):
try:
doc = yield people_db.get(user_id)
self.write('hello %s'%(doc['name']))
except NotFound:
self.write('hello whoever you are')
self.finish()
application = tornado.web.Application([
(r'/hi/([^/]+)', RelaxedHello),
]).listen(1920)
tornado.ioloop.IOLoop.instance().start()
我遇到的问题是,尽管couch文档非常好,但我还是收到了一个badyieldror。我怀疑这和龙卷风.gen模块设置不正确(或其他原因?)。使用灯芯绒而不使用@relax decorator,并带有回调函数。在
^{pr2}$
阅读the code for relax和{a2},在我看来,灯芯绒3年前的代码并不是为最现代的龙卷风习语设计的。具体来说,
get
接受回调,而不是像现代Tornado api那样返回Future
。在这意味着您必须使用与
gen.Task
类似的旧样式:我还没有测试过,告诉我情况如何。More info on ^{} is in the Tornado documentation 。在
相关问题 更多 >
编程相关推荐