0

How can I have more than one loop running ate the same time using the same function but using different parameters like:

@tasks.loop(seconds = 10)
async def loop(name):
    Print(name)

loop.start("Jon")
loop.start("Joseph")

Is this how u pass parameters to loops?

Tiago Oliveira
  • 47
  • 1
  • 12

1 Answers1

-1

You need to create a new Loop object for each loop. You can do this by using regular function calling repeatedly instead of the decorator:

async def loop(name):
    print(name)

names = ["Jon", "Joseph"]

loops = {name: tasks.loop(seconds=10)(name) for name in names}
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96