Summary
Add asyncio.Task.cancelling_since(), a method returning the event loop time
at which Task.cancel() was first called, or None if cancellation has not
been requested.
Motivation
Task.cancelling() exposes how many cancellation requests were made, but not
when the first request happened. That makes it difficult to:
- measure how long a task remains pending after cancellation is requested
- debug timeout and cancellation latency
- emit metrics around delayed cancellation handling in long-running async systems
Proposed API
task.cancelling_since() -> float | None
Returns loop.time() captured at the first cancel() call, or None if
cancel() has not been called. Repeated cancel() calls do not overwrite the
original timestamp.
Notes
This records when cancellation was requested, not when the task actually
finished cancelling.
Linked PRs
Summary
Add
asyncio.Task.cancelling_since(), a method returning the event loop timeat which
Task.cancel()was first called, orNoneif cancellation has notbeen requested.
Motivation
Task.cancelling()exposes how many cancellation requests were made, but notwhen the first request happened. That makes it difficult to:
Proposed API
task.cancelling_since() -> float | NoneReturns
loop.time()captured at the firstcancel()call, orNoneifcancel()has not been called. Repeatedcancel()calls do not overwrite theoriginal timestamp.
Notes
This records when cancellation was requested, not when the task actually
finished cancelling.
Linked PRs