Python Multithreading-Events

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.