RaNdOm_PErsOn159
RaNdOm_PErsOn159

Reputation: 21

How to make a loop without stopping the code execution

I was making a discord bot and wanted to make a timer, but without using a loop. The problem with a loop is that it would stop the rest of the circuit until it's done executing the loop. Is there a way to get around this? I did search how to do it, but all of them used while x > 60 which would not work in this case.

Upvotes: 0

Views: 655

Answers (1)

Eimantas G
Eimantas G

Reputation: 467

You need to use threads, and that would look something like this:

import threading

def func():
    times = 0
    while times < 10:
        print(times)
        times += 1;

x = threading.Thread(target=func)
x.start()

n = 100

while n < 110:
    n += 1
    print(n)

Here both while loops run at the same time

Upvotes: 3

Related Questions