0
@my_group.child
@lightbulb.command('five', '5 minute countdown')
@lightbulb.implements(lightbulb.SlashSubCommand)
async def subcommand(ctx):
    await ctx.respond("Timer for 5 minute⌛ start!")
    await ctx.respond("https://upload.wikimedia.org/wikipedia/commons/7/7a/Alarm_Clock_GIF_Animation_High_Res.gif")
    for i in range(5*60):
        time.sleep(1) #5 min
        if i % 60 == 0 and i != 0:
            await ctx.respond(str(int(i/60)) + " minute⌛ has passed!")
    await ctx.respond("Timer ended!")

@my_group.child
@lightbulb.command('ten', '10 minute countdown')
@lightbulb.implements(lightbulb.SlashSubCommand)
async def subcommand(ctx):
    await ctx.respond("Timer for 10 minute⌛ start!")
    await ctx.respond("https://upload.wikimedia.org/wikipedia/commons/7/7a/Alarm_Clock_GIF_Animation_High_Res.gif")
    for i in range(10*60):
        time.sleep(1) #10 min
        if i % 60 == 0 and i != 0:
            await ctx.respond(str(int(i/60)) + " minute⌛ has passed!")
    await ctx.respond("Timer ended!")

@my_group.child
@lightbulb.command('thirty', '30 minute countdown')
@lightbulb.implements(lightbulb.SlashSubCommand)
async def subcommand(ctx):
    await ctx.respond("Timer for 30 minute⌛ start!")
    await ctx.respond("https://upload.wikimedia.org/wikipedia/commons/7/7a/Alarm_Clock_GIF_Animation_High_Res.gif")
    for i in range(30*60):
        time.sleep(1) #30 min
        if i % 300 == 0 and i != 0:
            await ctx.respond(str(int(i/300)) + " minute⌛ has passed!")
    await ctx.respond("Timer ended!")

When run, the timer will start however every other script is unable to run due to it being stuck in the for loop while the timer is still going. Is there an alternate way of making a timer that won't stop other scripts from running?

1 Answers1

0

The issue here is probably that your threads while sleeping, are not releasing the resources for the other threads.

It should work once you change the time.sleep(1) to await asyncio.sleep(1)

You can find more information here and here.

Gleb
  • 23
  • 4