Event loops should have an id/name and mention it in errors

When using an event loop per thread, I ran into the following issue:

      RuntimeError: Task <Task pending name='Task-8' coro=<BaseHTTPMiddleware.call_next.<locals>.coro() running at /xxx/.venv/lib/python3.8/site-packages/starlette/middleware/base.py:38>> got Future <Future pending cb=[shield.<locals>._outer_done_callback() at ~/.pyenv/versions/3.8.1/lib/python3.8/asyncio/tasks.py:884]> attached to a different loop

To debug I had to print asyncio.get_event_loop()._selector to find where the loops were being used.

I couldn’t find a public method/prop to identify the loops.

So in this error message, it would be helpful to identify which loop is being used.

Also would be useful for logging. LogRecord should have an event loop prop so that it can easily be added to a formatter.

1 Like