Reputation: 1847
Could someone pls explain to me what’s going on here ? I wanted to add a message to the timeout error:
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) looks like this :
def result(self, timeout=None):
# bla bla bla
else:
raise TimeoutError()
However when the timeout occurs my try/except clause doesn’t catch the Timeout. In fact
future = asyncio.run_coroutine_threadsafe(do_stuff(), loop=loop)
try:
return future.result(timeout=3)
except Exception as e:
log.error(str(e))
shows empty e
. WTH?
Upvotes: 3
Views: 936
Reputation: 1847
OK. I know. I should be using except asyncio.TimeoutError:
, not the base TimeoutError
.
Upvotes: 4