Thread events are used for thread control threads, and the initial value of thread events is false
Set: Sets the value of the thread event to True
Clear: Set the value of the thread event to False
#-*-Coding:utf-8-*-__author__ = "MuT6 sch01ar" import threadingimport timeevent = Threading. Event () def myevent (): count = 1 event.set () while True: if Count >5 and Count <10: Event.clear () #清空标志位 print ("Event has Been clean!") Elif count >10: event.set () #设置标志位 count = 0 Print ("event has Been set!") else: print ("This is a event test!") Time.sleep (1) count +=1def myevent_test (): While True: if Event.is_set (): #如果标志位被设置 Print ("[The Event is Set] ") time.sleep (1) else: print (" [The event Isn ' t set] ") event.wait () #等待标志位被设置 Print ("The Event Been Set Again") event_1 = Threading. Thread (target=myevent) event_1.start () Event_2 = Threading. Thread (target=myevent_test) Event_2.start ()
Python Multithreading-Events