Skip to content

Instantly share code, notes, and snippets.

@romuald
Created November 2, 2018 14:00
Show Gist options
  • Save romuald/eb71ef6dcb8af5f464b29727c3a9542d to your computer and use it in GitHub Desktop.
Save romuald/eb71ef6dcb8af5f464b29727c3a9542d to your computer and use it in GitHub Desktop.
python asyncio shield decorator
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
@giuliano-macedo
Copy link

Why this isn't std ? 0.o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment