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

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -