有时在使用async/await
语法后,我发现程序不再正常工作。但也没有例外。
例如:
async def my_func(self):
async with self.engine() as conn:
print('step1') # step1 shows in console
await conn.exceute("INSERT INTO bla-bla")
print('step2') # I can't watch 'step2', and no any exceptions caughted to console
但是如果我使用try/except
语法异常可以被捕获:
所以。我能立即看到异常而不被抓住吗?或者我只能使用步骤来调试?在
引发异常,展开堆栈。在
真正的问题是:你用什么来管理你的合作计划?在
loop.run_until_complete(my_func())
将按预期处理异常。另一种使用场景可能有所不同。在相关问题 更多 >
编程相关推荐