--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Waldecir
class Rate(Model):def handle_response(self, response, error, callback):assert callback, iscallableif error:raise errorelse:callback(response)
@return_futuredef latest_rates(self, db, callback):
db.rates.find_one({}, callback=functools.partial(self.handle_response, callback=callback))
Waldecir
{
[
user_id : ObjectID(XXXXXXXXXX),
rate: { xxx: yyyyy, zzzz: ccccc}
]
Waldecir
@return_futuredef get(self, db, id, callback):db.users.find_one({"_id": id}, callback=functools.partial(self.handle_response, callback=callback))@return_future@gen.coroutinedef latest_rates(self, db, callback):rates = []cursor = db.rates.find()while (yield cursor.fetch_next):m_rate = cursor.next_object()m_user = yield self.get(db, m_rate['rater_id'])rates.append("xxx")callback(rates)
Traceback (most recent call last):File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/web.py", line 1055, in _stack_context_handle_exceptionraise_exc_info((type, value, traceback))File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/stack_context.py", line 239, in wrappedcallback(*args, **kwargs)File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/web.py", line 1187, in future_completef.result()File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/concurrent.py", line 129, in resultraise_exc_info(self.__exc_info)File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/stack_context.py", line 270, in _nestedif exit(*exc):File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/stack_context.py", line 180, in __exit__return self.exception_handler(type, value, traceback)File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/concurrent.py", line 211, in handle_errorfuture.set_exc_info((typ, value, tb))File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/concurrent.py", line 125, in set_exc_infoself.set_exception(exc_info[1])File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/concurrent.py", line 87, in set_exceptionself._set_done()File "/Users/wsantos/.virtualenvs/rating/lib/python2.7/site-packages/tornado/concurrent.py", line 95, in _set_donefor cb in self._callbacks:TypeError: 'NoneType' object is not iterable
Waldecir
if i remove @return_futures and callback from latest_rates i can print all fine, i dont know to return now., and i dont know why documentation say to not user coroutine and return_future together, can you explain Ben, i think would be good to explain too in docs.
@gen.coroutinedef latest_rates(self, db):
rates = []cursor = db.rates.find()while (yield cursor.fetch_next):m_rate = cursor.next_object()m_user = yield self.get(db, m_rate['rater_id'])rates.append("xxx")
raise gen.Return(rates)
Waldecir