无法使用MongoTor获得连接

时间:2012-11-07 10:29:39

标签: mongodb asynchronous tornado

我正在尝试使用MongoTor

更改我的代码以使其异步

这是我的简单代码:

class BaseHandler(tornado.web.RequestHandler):
    @property 
    def db(self):
        if not hasattr(self,"_db"):
            _db = Database.connect('localhost:27017', 'essog')
            return _db
    @property
    def fs(self):
        if not hasattr(BaseHandler,"_fs"):
            _fs = gridfs.GridFS(self.db)
            return _fs


class LoginHandler(BaseHandler):
    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        email = self.get_argument("email")
        password = self.get_argument("pass1")
        try:
            search = yield tornado.gen.Task(self.db.users.find, {"prs.mail":email})
            ....

我收到了这个错误:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\web.py", line 1043, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\web.py", line 1162, in wrapper
return method(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 122, in wrapper
runner.run()
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg\tornado\gen.py", line 365, in run
yielded = self.gen.send(next)
File "G:\Mon projet\essog\handlers.py", line 92, in post
search = yield tornado.gen.Task(self.db.users.find, {"prs.mail":email})
File "G:\Mon projet\essog\handlers.py", line 62, in db
_db = Database.connect('localhost:27017', 'essog')
File "build\bdist.win-amd64\egg\mongotor\database.py", line 131, in connect
database.init(addresses, dbname, read_preference, **kwargs)
File "build\bdist.win-amd64\egg\mongotor\database.py", line 62, in init
ioloop_is_running = IOLoop.instance().running()
 AttributeError: 'SelectIOLoop' object has no attribute 'running'
 ERROR:tornado.access:500 POST /login (::1) 3.00ms

这是另一个问题,在这种情况下如何制作distinct

以下是阻止模式

的作用
search = self.db.users.find({"prs.mail":email}).distinct("prs.mail")[0]

更新

似乎没有Tornado运行时会发生此错误!在控制台中仅使用模块时出现的错误相同。

  

test = Database.connect(“localhost:27017”,“essog”)   -------------------------------------------------- ------------------------- AttributeError Traceback(最近一次调用   最后)in()   ----> 1 test = Database.connect(“localhost:27017”,“essog”)

     

C:\ Python27 \ lib中\站点包\ mongotor-0.0.10-py2.7.egg \ mongotor \ database.pyc   在连接(cls,地址,dbname,read_preference,** kwargs)       131       132 database = Database()    - > 133 database.init(address,dbname,read_preference,** kwargs)       134       135返回数据库

     

C:\ Python27 \ lib中\站点包\ mongotor-0.0.10-py2.7.egg \ mongotor \ database.pyc   在init(self,addresses,dbname,read_preference,** kwargs)        60个self._nodes.append(节点)        61   ---> 62 ioloop_is_running = IOLoop.instance()。running()        63 self._config_nodes(callback = partial(self._on_config_node,   ioloop_is_running))        64

     

AttributeError:'SelectIOLoop'对象没有属性'running'

1 个答案:

答案 0 :(得分:0)

我得到了asnwer:

  1. 现在,Tornado 2.4post1已经删除了running(),所以要使用实际的MongoTor,请使用tornado 2.4
  2. 编辑:龙卷风和mongotor现在使用最新版本更好。

    1. using distinct

      distinc_uuids = yield gen.Task(db.collection_test.find({"param":'shouldbeparam1'}).distinct, 'uuid')