Created
July 2, 2020 13:26
-
-
Save njsmith/efcde14a02b0105bd1b2c556aa5266a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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