I'm trying to implement the following pattern:

async def test(i): 
    time.sleep(10)
    print("Ready", i)

i = 0
while True:
    print("New iteration")
    #here I want to call test function asynchronously in a loop and go to the next iteration
    #if previous test execution is completed:
        asyncio.run(test(i))
    i += 1

Expected output would be:

New iteration
New iteration
...
New iteration
Ready, 14235
New iteration
New iteration
...
New iteration
Ready, 29513
New iteration 
...

I've got two problems. First of all, I don't know how to check whether test function has been finished. The second problem is that "i+=1" seems not to be executed until test(i) is completed. I don't want to wait for it.

Is it possible to achieve what I need either with asyncio or multiprocessing packages?

0 Answers