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