Update variable in Threads in real time as variable updates outside Thread

Viewed 16

So I have a variable that constantly changes in main scope, then I need a thread that checks if the variable that is updated is a certain value. My code looks like this

def check():
    global a
    print(if a == 2)

Thread(target=check).start()
while True:
    time.sleep(1)
    a = random.randint(3)

But in the Thread the a variable does not change while the main a is constantly changing.

Is there any way to fix this?

0 Answers
Related