我编写了以下简化版本的代码:
from sys import exit
from tornado.ioloop import IOLoop
from tornado.gen import coroutine
from pymongo.errors import CollectionInvalid
from motor import MotorClient
client = MotorClient()
db = client.db_test
coll_name = 'coll_test'
coll = db[coll_name]
cursor = None
@coroutine
def stop():
yield cursor.close()
client.disconnect()
IOLoop.current().stop()
exit()
@coroutine
def create_cursor():
global cursor
try:
yield db.create_collection(coll_name, capped=True, size=1000000)
except CollectionInvalid:
print('Database alredy exists!')
yield coll.save({})
yield coll.save({})
cursor = coll.find(tailable=True, await_data=True)
yield cursor.fetch_next
cursor.next_object()
if __name__ == "__main__":
IOLoop.current().spawn_callback(create_cursor)
IOLoop.current().call_later(10, stop)
IOLoop.current().start()
当我运行它时,我随机没有得到这两个错误或其中之一:
Exception ignored in: <bound method MotorCursor.__del__ of MotorCursor(<pymongo.cursor.Cursor object at 0x7fd3a31e5400>)>
Traceback (most recent call last):
File "./env/lib/python3.4/site-packages/motor/__init__.py", line 1798, in __del__
TypeError: 'NoneType' object is not callable
Exception ignored in: <bound method MotorCursor.__del__ of MotorCursor(<pymongo.cursor.Cursor object at 0x7f4bea529c50>)>
Traceback (most recent call last):
File "./env/lib/python3.4/site-packages/motor/__init__.py", line 1803, in __del__
File "./env/lib/python3.4/site-packages/motor/__init__.py", line 631, in wrapper
File "./env/lib/python3.4/site-packages/tornado/gen.py", line 204, in wrapper
TypeError: isinstance() arg 2 must be a type or tuple of types
我正在使用 Python 3.4.3、Tornado 4.1、Pymongo 2.8、Motor 0.4.1 和 MongoDB 2.6.3。
tailable
仅当和await_data
选项True
位于光标创建时才会出现此问题。
当我不关闭光标时,我也会收到 Pymongo 的错误。但我认为我应该明确关闭它,因为它是一个可尾游标。
我用谷歌搜索了它,但我没有运气。有什么建议么?