繁体   English   中英

在Python REPL中测试异步Tornado代码

[英]Testing async Tornado code in the Python REPL

说我有一些使用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服务器等的一部分运行良好,但是如何从REPL中运行此功能(具有REPL块/等待完成,就好像它不是异步的一样)来进行调试?

在我写作时发现了它:

tornado.ioloop.IOLoop.instance().run_sync(lambda: translateSimple(text, cmds))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM