Examining the test suite for PyMongo I see a test using max_time_ms and trapping an ExecutionTimeout exception when calling cursor.next() or list(cursor). In my own testing I have never been able to get find queries I run to generate this exception; they wait and time out in the given period of time, but they instead simply raise StopIteration without any way to identify if is due to a timeout or simply running out of data. This is especially critical for my use of capped collections as a queue.
My test case:
import pymongo db = pymongo.Connection().test db.sample.drop() db.create_collection('sample', capped=True, size=4 * 1024 * 1024, max=5000) collection = db.sample collection.insert({'nop': True}) # Capped collections need one value before you can tail them. cursor = collection.find({}, tailable=True, await_data=True).max_time_ms(2 * 1000) __import__('pprint').pprint(list(cursor)) # Should explode with ExecutionTimeout.