Error handling 尝试/除了不捕捉未来';s时间误差

Error handling 尝试/除了不捕捉未来';s时间误差,error-handling,timeout,python-3.6,python-asyncio,try-except,Error Handling,Timeout,Python 3.6,Python Asyncio,Try Except,有人能给我解释一下这里发生了什么事吗? 我想在超时错误中添加一条消息: 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()(concurr

有人能给我解释一下这里发生了什么事吗? 我想在超时错误中添加一条消息:

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.\u 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
。好的。我知道。除了asyncio.TimeoutError:,我应该使用
,而不是基
TimeoutError

e
:因为
TimeoutError
是在没有任何参数的情况下创建的
TimeoutError()
。真的不需要它们,它出错的事实足以说明出了什么问题。