Add an expired property
asvetlov opened this issue · 3 comments
asvetlov commented
- Context manager should return itself from
__enter__
. expired
property should returnTrue
if timeout expired.
The change allows to figure out is asyncio.TimeoutError
was raised by context manager itself or internal code, e.g.
try:
async with timeout(1.0) as cm:
await fetch()
except asyncio.TimeoutError:
if cm.expired:
# top level timeout
else:
# `fetch()` raised timeout itself
@hellysmile we discussed the change offline.
Do you agree with proposed API?
hellysmile commented
Looks perfect. Another way is just bool(cm)
, not sure is it clear or nor
asvetlov commented
Explicit property is better I believe.