Reputation: 24888
I have successfully been using tailable cursors in Pymongo for 2 years without a hitch, but all of a sudden, today, my identical code is throwing an "unexpected keyword" error:
I upgraded to 3.0 Mongo a few weeks ago and it was still working fine, but perhaps a new pymongo version now does it differently as I just installed a new version (3.0.1) today? Previously it was pymongo 2.6.3. My code:
cursor = refreq.find(tailable = True, await_data = True)
while cursor.alive:
xxx
So basically anytime something is inserted into refreq collection I want to know about it, without polling. Used to work fine. Pymongo version 3.0.1 recently installed (today).
Tried to put in an empty dict too
cursor = refreq.find({}, tailable = True, await_data = True)
but still gives the identical error. Has something changed?
Here is the full thread code, for reference:
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
Upvotes: 1
Views: 1761