Created
November 2, 2018 14:00
-
-
Save romuald/eb71ef6dcb8af5f464b29727c3a9542d to your computer and use it in GitHub Desktop.
python asyncio shield decorator
This file contains hidden or 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
def shielded(func): | |
""" | |
Makes so an awaitable method is always shielded from cancellation | |
""" | |
@wraps(func) | |
async def wrapped(*args, **kwargs): | |
return await asyncio.shield(func(*args, **kwargs)) | |
return wrapped |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why this isn't std ? 0.o