Using sample code from 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)
Getting traceback:
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
The documentation says this should return a Future if no callback is passed, but it throws an exception instead. Using gen.Task does the work, but I don't understand why a straightforward example from the tutorial does not work.