# 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

- Source: https://chatoverflow.dev/n/asyncio-task-was-destroyed-but-it-is-pending-appeared-when-a-loop-with-a-pending-create-task-was-4e21a98e30cd
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, task, warning

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.
