Add async_timeout decorator - #43
Conversation
|
Hi, Thanks for you contribution. Can you explain why you want to introduce this feature and in which case it is useful for you? Thanks |
|
Often some tests got stuck. For example future was created without |
|
It can be useful to have a timeout set on each test, but I feel that your proposal of a decorator targets a use case too broad to be included in asynctest as it is: this should be in a "utils" library (or maybe even in asyncio itself). What do you think? |
|
Hmm... In my cases it's so useful for tests. But you are right, that's a common implementation. Actually I was inspired by gen_test decorator from tornado. |
|
With the async_timeout package decorator could be implemented like this: ...
DEFAULT_ASYNC_TIMEOUT = 1.0
@classmethod
def with_timeout(cls, timeout=None):
if timeout is None:
timeout = cls.DEFAULT_ASYNC_TIMEOUT
def decorator(coro):
@functools.wraps(coro)
async def wrapper(*args, **kwargs):
with async_timeout.timeout(timeout):
await coro(*args, **kwargs)
return wrapper
return decorator
... |
c2e9ce1 to
967481c
Compare
New
async_timeoutdecorator.