pymongo中的Tailable光标似乎已停止工作

Tho*_*wne 1 python mongodb pymongo

我已经成功地在Pymongo使用了2年的tailable游标,但突然间,今天,我的相同代码抛出了"意外的关键字"错误:

在此输入图像描述

我几周前升级到3.0 Mongo并且它仍然工作正常,但是现在可能是一个新的pymongo版本,因为我今天刚刚安装了新版本(3.0.1)?以前是pymongo 2.6.3.我的代码:

cursor = refreq.find(tailable = True, await_data = True)
while cursor.alive:
    xxx
Run Code Online (Sandbox Code Playgroud)

所以基本上任何时候插入refreq集合的东西我想知道它,没有轮询.习惯工作正常.最近安装了Pymongo 3.0.1版(今天).

试图插入一个空的字典

cursor = refreq.find({}, tailable = True, await_data = True)
Run Code Online (Sandbox Code Playgroud)

但仍然给出相同的错误.有什么变化?

这是完整的线程代码,供参考:

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
Run Code Online (Sandbox Code Playgroud)

Joh*_*yHK 6

在pymongo 3.0中,为此选择find一个cursor_type选项.在tailableawait_data参数已被删除.

所以它应该是:

cursor = refreq.find(cursor_type = CursorType.TAILABLE_AWAIT)
Run Code Online (Sandbox Code Playgroud)