2021-07-25 21:52:13 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import anyio
|
2021-07-25 23:29:20 -07:00
|
|
|
from functools import wraps
|
2021-07-25 21:52:13 -07:00
|
|
|
|
|
|
|
def shield(f):
|
2021-07-25 23:29:20 -07:00
|
|
|
@wraps(f)
|
2021-07-25 21:52:13 -07:00
|
|
|
async def shielded(*args, **kwargs):
|
2021-07-25 23:29:20 -07:00
|
|
|
with anyio.CancelScope(shield=True):
|
2021-07-25 21:52:13 -07:00
|
|
|
return await f(*args, **kwargs)
|
|
|
|
return shielded
|