2015-04-29 97 views
0

我已经成功地使用tailable游标Pymongo 2年顺利工作,但所有的突然,今天,我相同的代码抛出一个“意外的关键字”错误:Tailable光标似乎已经停止

enter image description here

我在几个星期前升级到3.0蒙戈和它仍然工作正常,但也许现在新版本pymongo做它不同的,因为我(3.0.1)今天刚刚安装了一个新的版本?以前它是pymongo 2.6.3。我的代码:

cursor = refreq.find(tailable = True, await_data = True) 
while cursor.alive: 
    xxx 

所以基本上任何时候的东西插入refreq收集我想知道这件事情,没有投票。用于正常工作。 Pymongo版本3.0.1最近安装(今天)。

试图把一个空的字典也

cursor = refreq.find({}, tailable = True, await_data = True) 

,但仍然给出了相同的错误。有什么改变?

这里是全螺纹代码,以供参考:

def handleRefRequests(db, refqueue): 
    """ handles reference data requests. It's threaded. Needs the database id. 
    will create a capped collection and constantly poll it for new requests""" 
    print("Dropping the reference requests collection") 
    db.drop_collection("bbrefrequests") 
    print("Recreating the reference requests collection") 
    db.create_collection("bbrefrequests", capped = True, size = 100 * 1000000) # x * megabytes 
    refreq = db.bbrefrequests 
    # insert a dummy record otherwise exits immediately 
    refreq.insert({"tickers":"test", "fields":"test", "overfields":"test", "overvalues":"test", "done": False}) 
    cursor = refreq.find({}, tailable = True, await_data = True) 
    while cursor.alive: 
     try: 
      post = cursor.next() 
      if ("tickers" in post) and ("fields" in post) and ("done" in post): # making sure request is well formed 
       if post["tickers"] != "test": 
        refqueue.put(post) 
     except StopIteration: 
      time.sleep(0.1) 
     if not runThreads: 
      print("Exiting handleRefRequests thread") 
      break 

回答

5

在pymongo 3.0,find需要cursor_type选项此。 tailableawait_data参数已被删除。

所以它应该是:

cursor = refreq.find(cursor_type = CursorType.TAILABLE_AWAIT) 
+0

是的 - 刚刚从pymongo导入,这样从pymongo进口MongoClient,CursorType的,并且它按照你的答案再次合作。 –