Python process,queue

Source: Internet
Author: User

1 #-*-coding:utf-8-*-2  fromMultiprocessingImportProcess,queue3 ImportOs,time,random4 defWrite (q):5      forValueinch['A','B','C']:6         Print  'Put%s to Queue...and Ospid is%s'%(Value,os.getpid ())7 q.put (value)8 Time.sleep (Random.random ())9 defRead (q):Ten      whileTrue: OneValue =q.get (True) A         Print 'Get%s from Queue.and ospid is%s'%(Value,os.getpid ()) -  -  the if __name__=='__main__': -q=Queue () -PW = Process (target=write,args=(q,)) -PR = Process (target=read,args=(q,)) + Pw.start () - Pr.start () + Pw.join () A pr.terminate () at     Print 'Main Processes is' andOs.getpid ()

Results:

Put A to Queue...and Ospid is 7556
Get A from Queue.and ospid is 7324
Put B to Queue...and Ospid is 7556
Get B from Queue.and ospid is 7324
Put C-Queue...and ospid is 7556
Get C from Queue.and ospid is 7324
7380

Python process,queue

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.