According to a few examples online, in order to run asynchronous methods decorated with tornado.gen.coroutine from synchronous code, you can use following:
@tornado.gen.coroutine
def do_something():
do_something
if __name__ == "__main__":
tornado.ioloop.IOLoop.instance().run_sync(do_something)
However if you have arguments to coroutine method, is there a way to run it?
Yes:
@tornado.gen.coroutine
def do_something(arg):
do_something
if __name__ == "__main__":
tornado.ioloop.IOLoop.instance().run_sync(lambda: do_something(1))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With