【发布时间】:2018-01-15 11:57:26
【问题描述】:
有人可以向我解释这里发生了什么吗? 我想在超时错误中添加一条消息:
future = asyncio.run_coroutine_threadsafe(do_stuff(), loop=loop)
try:
return future.result(timeout=3)
except TimeoutError:
raise TimeoutError("Time out occurred while doing stuff")
future.results() (concurrent.futures._base.py) 看起来像这样:
def result(self, timeout=None):
# bla bla bla
else:
raise TimeoutError()
但是当超时发生时,我的 try/except 子句没有捕捉到超时。其实
future = asyncio.run_coroutine_threadsafe(do_stuff(), loop=loop)
try:
return future.result(timeout=3)
except Exception as e:
log.error(str(e))
显示空的e。 WTH?
【问题讨论】:
-
empty
e:因为TimeoutError是在没有任何参数TimeoutError()的情况下创建的。真的不需要它们,它出错的事实足以表明出了什么问题。
标签: error-handling timeout python-3.6 python-asyncio try-except