Skip to content

Instantly share code, notes, and snippets.

@njsmith
Created July 2, 2020 13:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njsmith/efcde14a02b0105bd1b2c556aa5266a6 to your computer and use it in GitHub Desktop.
Save njsmith/efcde14a02b0105bd1b2c556aa5266a6 to your computer and use it in GitHub Desktop.
class EnterTimeout:
def __init__(self, async_cm, timeout):
self._async_cm = async_cm
self._timeout = timeout
async def __aenter__(self):
with fail_after(self.timeout):
return await self._async_cm.__aenter__()
async def __aexit__(self, *args):
return await self._async_cm.__aexit__(*args)
async with EnterTimeout(some_cm, 10):
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment