我刚开始了一个使用Tornado和asyncmongo的项目。在
我有一个具有异步方法的处理程序。在里面我在向mongo询问一些词:
@tornado.web.asynchronous
def get(self):
word = self.get_argument('word', None)
if not word:
self.write('{}')
self.finish()
self.db.spanish_dict.find({'$or': [{'word': word}, {'stem': word}]},
callback=self._on_response)
def _on_response(self, response, error):
# need to sort response by relevancy
在我的回调方法中,我需要原始单词来准确地对mongo结果进行排序。在
我找到了thispost,它使用functools.partial
来完成这项工作,允许我向回调方法传递其他参数
我想知道在get
方法中设置实例属性并在_on_response
中访问它是否有任何不利影响?谢谢
使用龙卷风.gen你完全回避了这个问题
http://www.tornadoweb.org/documentation/gen.html?highlight=tornado.gen#tornado.gen
相关问题 更多 >
编程相关推荐