Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tornado, run coroutine method with arguments from synchronous code

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?

like image 558
shicky Avatar asked Dec 25 '22 16:12

shicky


1 Answers

Yes:

@tornado.gen.coroutine
def do_something(arg):
   do_something

if __name__ == "__main__":
    tornado.ioloop.IOLoop.instance().run_sync(lambda: do_something(1))
like image 90
A. Jesse Jiryu Davis Avatar answered Dec 29 '22 05:12

A. Jesse Jiryu Davis