In the process of using multiple processes, it is best not to use shared resources, if you have to use them, please look down. There are three ways to share resources in the Multiprocessing class, namely Queue, Array, and Manager. These three are all components of Multiprocessing and are very convenient to use. Note: Normal global variables cannot be shared by child processes. Only data structures constructed by the Multiprocessing component can be shared.
Use Multiprocessing.Queue class, share memory (Process class only)
Disadvantages: Can no longer be used in the Pool process pool.
Use Multiprocessing.Array class, share memory (only for Process class)
Disadvantages: Cannot be used with Pool.
Use the Multiprocessing.Manager class to share resources. (Can be applied to the Pool class)
Note: Due to the Windows operating system, the code for creating the Multiprocessing class object must be placed under the main() function, but linux does not need to be used, so the two versions are distinguished here.
Example Purpose: The parent process synchronously determines a common resource value during the execution of the child process, and terminates all processes if the condition is met.
Advantages: It can be used with Pool and it is faster.
Description: Compared with the linux version code, the code under windows puts the reference to the list after main(), because Windows can only refer to multiple processes under the main function. When the child process is instantiated, the Manager object must be passed to the child process, otherwise the lists cannot be shared, and this process consumes huge resources, so the performance is very poor.
Disadvantages: The speed is very slow, so in Windows you want to end all processes ahead of time, you can use the way to get the return value, refer to [Multiprocessing subprocess return value] (http://thief.one/2016/11/24/Multiprocessing sub Process return value)
[Multiprocessing Series] Shared Resources
[[Multiprocessing Series] Subprocess Return Value] (http://thief.one/2016/11/24/Multiprocessing%E5%AD%90%E8%BF%9B%E7%A8%8B%E8%BF%94 %E5%9B%9E%E5%80%BC/)
[[Multiprocessing Series] Multiprocessing Basics] (http://thief.one/2016/11/23/Python-multiprocessing/)