I'm starting to learn writing multithreaded python code. In particular I'm trying to use events between thread. For some reason the code below is not working and I can't find out why. Do you have any suggestion? Thank you in advance!
import threading
import time
e1 = threading.Event()
def counting_thread():
x=0
while 1:
print(x)
if x==5:
e1.set
x=x+1
if x==11:
x=0
time.sleep(1)
def speaking_thread():
while not e1.wait():
print('You just said five!')
t1 = threading.Thread(target=counting_thread)
t1.start()
t2 = threading.Thread(target=speaking_thread)
t2.start()
You didn't actually call the set
method.
if x==5:
e1.set()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.