async def async_fn(): task = await ag.get_current_task() async with ag.cancel_protection(): task.cancel() await ag.sleep_forever() await ag.sleep_forever() pytest.fail("Failed to cancel")
async def async_func(ctx): if call_cancel: ctx['task'].cancel() if protect: async with ag.cancel_protection(): await ag.checkpoint() else: await ag.checkpoint()
async def protect(e): import asyncgui async with asyncgui.cancel_protection(): await e.wait()
async def inner_fn(e): assert task._cancel_protection == 1 async with ag.cancel_protection(): assert task._cancel_protection == 2 await e.wait() assert task._cancel_protection == 1
async def outer_fn(e): async with ag.cancel_protection(): await inner_fn(e) await ag.sleep_forever() pytest.fail("Failed to cancel")
async def async_fn(e): async with ag.cancel_protection(): await e.wait() await ag.sleep_forever() pytest.fail("Failed to cancel")
async def finish_soon_but_protected(e): import asyncgui as ag async with ag.cancel_protection(): await e.wait()