Things to check first
AnyIO version
master (14356be)
Python version
CPython 3.13.7
What happened?
Cancelling a Future from BlockingPortal.start_task/BlockingPortal.start_task_soon does nothing if the portal has been requested to stop (portal.stop).
How can we reproduce the bug?
This test is nearly identical to test_start_task_soon_cancel_immediately, but with portal.call(portal.stop) added:
def test_start_task_soon_cancel_after_request_stop(
self, anyio_backend_name: str, anyio_backend_options: dict[str, Any]
) -> None:
cancelled = False
done_event = threading.Event()
async def event_waiter() -> None:
nonlocal cancelled
try:
await sleep(3)
except get_cancelled_exc_class():
cancelled = True
finally:
done_event.set()
with start_blocking_portal(anyio_backend_name, anyio_backend_options) as portal:
future = portal.start_task_soon(event_waiter)
portal.call(portal.stop)
future.cancel()
done_event.wait(10)
assert cancelled