说我有一些使用python3 tornado的异步函数定义的函数
@gen.coroutine
def translateSimple(toTranslate, commands):
proc_in, proc_out = startPipeline(commands)
yield gen.Task(proc_in.stdin.write, bytes(toTranslate, 'utf-8'))
proc_in.stdin.close()
translated = yield gen.Task(proc_out.stdout.read_until_close)
proc_in.stdout.close()
return translated.decode('utf-8')
- 作为龙卷风http服务器等的一部分,这可以正常运行,但是我如何从depp中运行这个功能(让repla block/等待直到完成,好像不是异步(来进行调试?
在我写作时找到了它:
tornado.ioloop.IOLoop.instance().run_sync(lambda: translateSimple(text, cmds))