簡體   English   中英

pymongo中的尾光標似乎已停止工作

[英]Tailable cursor in pymongo seems to have stopped working

我已經成功地在Pymongo中使用可尾光標兩年了,但是突然之間,今天,我相同的代碼拋出了“意外關鍵字”錯誤:

在此處輸入圖片說明

幾周前我升級到3.0 Mongo,它仍然可以正常工作,但是也許新的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

在pymongo 3.0中, find為此使用了cursor_type選項。 tailableawait_data參數已刪除。

所以應該是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM