我正在尝试使用Corduroy使用 python Tornado Web Server与 CouchDB 异步对话。
下面的代码来自灯芯绒指南,有一些改动。
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()
我遇到的问题是,尽管发现沙发文档非常好,但我收到了 BadYieldError。我怀疑这与 tornado.gen 模块设置不正确(或其他什么?)有关。在没有@relax 装饰器的情况下使用灯芯绒,并且使用回调可以正常工作。
Traceback (most recent call last):
File "c:\env\pymeals_tornado\lib\site-packages\tornado\web.py", line 1074, in wrapper
return method(self, *args, **kwargs)
File "c:\env\pymeals_tornado\lib\site-packages\corduroy\__init__.py", line 43, in _r_e_l_a_x_
return gen.engine(_func_)(*args, **kwargs)
File "c:\env\pymeals_tornado\lib\site-packages\tornado\gen.py", line 107, in wrapper
runner.run()
File "c:\env\pymeals_tornado\lib\site-packages\tornado\gen.py", line 319, in run
yielded = self.gen.throw(*exc_info)
File "test.py", line 10, in get
doc = yield people_db.get(user_id)
BadYieldError: yielded unknown object <Document 65d936ee54417e46479a908f7a0038ef[2] {name:Colin}>