Answer the question
In order to leave comments, you need to log in
How to run a function indefinitely in Python?
Hello!
There is a code:
import asyncio
from random import randint
async def worker():
if condition == False:
return False
await asyncio.sleep(randint(1,3))
return True
import asyncio
from random import randint
async def worker(i):
while True:
await asyncio.sleep(randint(1,3))
print(f'Worker #{i}')
loop = asyncio.get_event_loop()
futures = [loop.create_task(worker(str(i))) for i in range(5)]
loop.run_forever()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question