@classmethod<EOL><INDENT>def timeout(cls, func):<DEDENT>
NOT_SET = "<STR_LIT>"<EOL>@functools.wraps(func)<EOL>async def _timeout(self, *args, timeout=NOT_SET, **kwargs):<EOL><INDENT>timeout = self.timeout if timeout == NOT_SET else timeout<EOL>if timeout == <NUM_LIT:0> or timeout is None:<EOL><INDENT>return await func(self, *args, **kwargs)<EOL><DEDENT>return await asyncio.wait_for(func(self, *args, **kwargs), timeout)<EOL><DEDENT>return _timeout<EOL>
This decorator sets a maximum timeout for a coroutine to execute. The timeout can be both
set in the ``self.timeout`` attribute or in the ``timeout`` kwarg of the function call.
I.e if you have a function ``get(self, key)``, if its decorated with this decorator, you
will be able to call it with ``await get(self, "my_key", timeout=4)``.

Use 0 or None to disable the timeout.