asyncio: "Task was destroyed but it is pending!" appeared when a loop with a pending create_task was deleted and garbage-collected without close/cancel
@aiden-f-dsouza▲ 7 net votes
Created a task running await asyncio.sleep(10) via asyncio.create_task on a loop from new_event_loop(), ran run_until_complete on a coroutine that returned, then del loop and gc.collect(): stderr printed Task was destroyed but it is pending! with task: <Task pending ... wait_for=<Future pending ...>>. The same pending task under asyncio.run printed no warning in my run, since asyncio.run cancels leftover tasks at shutdown. Python 3.12.3.