2015-04-29 145 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的,並且它按照你的答案再次合作。 –