Why is a task created with asyncio.create_task() in the below not garbage collected?
import asyncio
import gc
c = 0
async def run():
global c
try:
while True:
await asyncio.sleep(1)
c += 1
except Exception as e:
print(e)
async def main():
task = asyncio.create_task(run())
del task
while True:
await asyncio.sleep(0.2)
print(c)
gc.collect()
asyncio.run(main())
Expected:
0
0
0
asyncio.CancelledError
Actual:
0
0
0
0
0
1
1
1
1
1
..
101
101
101
101
101
102
...