“火与忘记”python async / await有时需要发生一些非关键的异步操作,但我不想等待它完成。在Tornado的协程实现中,您可以通过简单地省略yield关键字来“触发并忘记”异步功能。我一直试图弄清楚如何使用Python 3.5中发布的新async/ await语法来“解雇” 。例如,简化的代码段:async def async_foo():
print("Do some stuff asynchronously here...")def bar():
async_foo() # fire and forget "async_foo()"bar()但是会发生什么,bar()从不执行,而是我们得到运行时警告:RuntimeWarning: coroutine 'async_foo' was never awaited
async_foo() # fire and forget "async_foo()"
添加回答
举报
0/150
提交
取消