所以我有这个代码:
import time
import threading
bar = False
def foo():
while True:
if bar == True:
print "Success!"
else:
print "Not yet!"
time.sleep(1)
def example():
while True:
time.sleep(5)
bar = True
t1 = threading.Thread(target=foo)
t1.start()
t2 = threading.Thread(target=example)
t2.start()
我试图理解为什么我不能bar
去.. 如果=
是true
这样,那么另一个线程应该看到变化并写Success!