python - Is this right way to call coroutine method in Tornado framework? -
i have websockethandler in tornado application. not sure right way make code asynchronous.
class myhandler(websockethandler): def open(self): ... self.my_coroutine_method() @gen.coroutine def my_coroutine_method(self): user = yield db.user.find_one() # call motor asynchronous engine self.write_message(user)
yes, correct. however, in cases calling coroutine without yielding can cause exceptions handled in unexpected ways, recommend using ioloop.current().spawn_callback(self.my_coroutine_method)
when calling coroutine non-coroutine this.
Comments
Post a Comment