Python multiprocessing standard library note points for using queue communication

Source: Internet
Author: User

Today originally wanted to study under the multiprocessing standard library of inter-process communication, according to the multiprocessing website to the hint, there are two ways to achieve inter-process communication, pipe and queue respectively. Because watching the queue pleasing to the eye, just want to take the queue to achieve, later, was the pit .... So I have this article.
I follow the Python standard library of Multiprocessing Library Research (1) in the code, the result is a constant error, death is not the result, see the program:

 fromMultiprocessingImportPool, QueuesImportOSdeffunc (MSG, q): Q.put ([MSG, None,'Hello'])    Print(Os.getpid ())if __name__=='__main__': Q=queues. Queue () Pool= Pool (4)     forIinchRange (4): Pool.apply_async (func, (i, Q,))Print("mark~ mark~ mark~~~~~~~~~~~~~~~~~~~~~~")    Print(Q.qsize ()) Pool.close () Pool.join ( )#call the close function before calling join, otherwise an error will occur. No new processes are added to the Pool,join function to wait for all child processes to end after the close is done     forIinchRange (Q.qsize ()):Print(Q.get ())

In fact, it's nothing, it's adding a queue object to the Apply_async function.
But it doesn't work anyway. I checked this article later. Python multi-process programming: Using Queue,pool to start a child process failure problem

Later on the official website carefully looked under, found:

So, I need to add a manager to catch up and try again ...

Python multiprocessing standard library note points for using queue communication

Related Article

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.