Python applet----Simple use of the queue module

Source: Internet
Author: User

def productor  (Myid,dataqueue,num_thread_per_productor): For i in range (Num_thread_per _productor):d ataqueue.put (' producer id:%s ==> %s '% (myid,i)) def consumer  (Myid,dataqueue, Stdoutlock): While true:try:data=dataqueue.get (Block=false) except queue. empty:passelse:with stdoutlock:print  (' Consumer%s get %s '% (myid,data)) if __name__== ' __main __ ': Import queue,threadingnumproductors=5num_thread_per_productor=5numconsumers=3dataque=queue. Queue () safeprint=threading. Lock () Waitfor=[]for i in range (numproductors):p roductor_thread=threading. Thread (target=productor,args= (I,dataque,num_thread_per_productor)) Productor_thread.start () Waitfor.append ( Productor_thread) For i in range (numconsumers): consumer_thread=threading. Thread (target=consumer,args= (i,dataque,safeprint)) Consumer_thread.daemon=true    consumer_ Thread.Start () For wait_thread in waitfor:wait_thread.join () print  (" ----------end-----------") 


This article is from the "a" blog, please make sure to keep this source http://lzs66.blog.51cto.com/9607068/1854735

Python applet----Simple use of the queue module

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.