Asyncio 收集 while 循环

Asyncio Gathering a while loop

这是我的代码的简化版本,但问题是一样的:

import asyncio

example = ["1", "2", "3", "4", "5"]

def test_1(numbers):
    while True:
        print(numbers)

tasks = []
async def test_2():
    for numbers in example:
        try:
            tasks.append(test_1(numbers))
        except:
            pass
    try:
        await asyncio.gather(*tasks)
    except:
        pass

asyncio.run(test_2())

我想做的是在 while 循环中同时打印所有项目,但是当我 运行 代码时它只打印第一个项目,因为它是循环的,有没有办法修好了吗?

好的,感谢@deceze,我修复了它,我以这种方式使用线程:

for numbers in example:
    t = threading.Thread(target=test_1, args=(numbers,))
    threads.append(t)
    t.start()