2
使用來自motor tutorial的示例代碼。電機錯誤:需要回撥
from tornado import gen
db = motor.MotorClient('localhost', 1235).open_sync().packmon
@gen.coroutine
def do_find():
cursor = db.test_collection.find()
for document in (yield cursor.to_list(length=100)):
print document
tornado.ioloop.IOLoop.current().run_sync(do_find)
獲取回溯:
Traceback (most recent call last):
File "app_main.py", line 51, in run_toplevel
File "chat.py", line 22, in <module>
tornado.ioloop.IOLoop.current().run_sync(do_find)
File "/home/user/venv/packmon-pypy/site-packages/tornado/ioloop.py", line 370, in run_sync
return future_cell[0].result()
File "/home/user/venv/packmon-pypy/site-packages/tornado/concurrent.py", line 129, in result
raise_exc_info(self.__exc_info)
File "/home/user/venv/packmon-pypy/site-packages/tornado/gen.py", line 221, in wrapper
runner.run()
File "/home/user/venv/packmon-pypy/site-packages/tornado/gen.py", line 507, in run
yielded = self.gen.send(next)
File "chat.py", line 19, in do_find
for document in (yield cursor.to_list(length=100)):
File "/home/user/venv/packmon-pypy/site-packages/motor/__init__.py", line 1465, in to_list
check_callable(callback, required=True)
File "/home/user/venv/packmon-pypy/site-packages/motor/__init__.py", line 74, in check_callable
raise TypeError("callback is required")
TypeError: callback is required
文檔說,如果沒有回調被傳遞,應返回一個未來,但它拋出一個異常來代替。使用gen.Task來完成這項工作,但我不明白爲什麼來自教程的直接示例不起作用。
後續:[電機0.2發佈](http://emptysqua.re/blog/motor-0-2-released/)於2014年4月,**現在** [[穩定]文檔](http ://motor.readthedocs.org/en/stable/tutorial.html)是0.2。 –