Python thread Event

Source: Internet
Author: User

A "flag" is defined globally, and if the "flag" value is False, then it blocks when the program executes the Event.wait method, and if the "flag" value is true, then the Event.wait method is no longer blocked.

Clear: Set "Flag" to False

Set: Sets "Flag" to True

With threading. Event implements inter-thread communication, using threading. Event allows a thread to wait for notifications from other threads, and we pass this event to the thread object,

Event has a flag built in by default and the initial value is false. Once the thread enters the waiting state through the wait () method until another thread calls the event's set () method to set the built-in flag to true, the event notifies all waiting-state threads to resume running.

Importthreading,timeevent=Threading. Event ()defAA ():Print('begin') event.wait ()Print('End') F=threading. Thread (target=aa) Event.clear ()#Although the event initial default value is False, it is customary to             #or set it up .F.start () time.sleep (10)#threads are blocked during this timeEvent.set ()

Python thread Event

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.