Measuring coroutine blocking time

I couldn’t find an easy way to measure how long an async coroutine blocks the event loop, so I rolled my own.

I use this in conjunction with a lag monitor to keep track of event loop health and identify the next best targets for optimization.

It’s difficult to maintain: every so often I come across a library that does something new that I haven’t accounted for. It breaks across different python versions sometimes too.

I noticed that there are some coroutine time measurements in CPython.

Is there any interest in exposing a standard way to measure coroutine blocking time? Feels like something that could be part of the standard library.

1 Like

Here are some discussions about this: