-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async_timeout decorator #43
base: master
Are you sure you want to change the base?
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_timeout
decorator.