asyncx.shield
- asyncx.shield(func)[source]
A decorator for an async function to protect it from being cancelled.
Example
>>> @asyncx.shield ... async def foo() -> None: ... print("Start foo") ... await asyncio.sleep(1) ... print("End foo") >>> coro = asyncio.create_task(foo()) >>> await asyncio.sleep(0.1) Start foo >>> coro.cancel() >>> await asyncio.sleep(1) End foo
- Arg:
func: An async function to be shielded.
- Parameters
func (Callable[[...], Awaitable[asyncx.shield.TReturn]]) –
- Return type
Callable[[…], Awaitable[asyncx.shield.TReturn]]