| 68 | |
| 69 | |
| 70 | class _CancellationObservedTask(asyncio.Task[_T]): # pragma: needs fcntl |
| 71 | def __init__( |
| 72 | self, |
| 73 | coroutine: Coroutine[None, None, _T], |
| 74 | cancellation_seen: threading.Event, |
| 75 | *, |
| 76 | loop: asyncio.AbstractEventLoop, |
| 77 | ) -> None: |
| 78 | self._cancellation_seen = cancellation_seen |
| 79 | super().__init__(coroutine, loop=loop) |
| 80 | |
| 81 | def cancel( |
| 82 | self, |
| 83 | msg: object | None = None, # simplint: ignore[imprecise-annotation] # Task.cancel accepts arbitrary payloads |
| 84 | ) -> bool: |
| 85 | # Task.cancel accepts arbitrary payloads; object is the narrowest accurate type for its public contract. |
| 86 | self._cancellation_seen.set() |
| 87 | return super().cancel(msg) |
| 88 | |
| 89 | |
| 90 | @NEEDS_FCNTL |
no outgoing calls