Python process
Advantage: can handle a large number of concurrent operations, using IO computing type
Cons: Because the data between processes is independent, creating a process consumes a portion of memory (the same process and CPU cores are the best)
Process: Processes (reminds me of 40 people, to burn 40 pots of water, to get 40 stoves, but high efficiency)
There is a join (2) blocked in the process, up to 2 seconds to block, Demaon (true) can be set without blocking, run directly.
All say that the data between processes is independent, then we can you share the data between the processes, intelligent human, of course, then use the mange and array
Arrary this thing is to convert a list into a special data type (array), manage way data sharing
fromMultiprocessingImportProcess fromMultiprocessingImportManagerImport Timeif __name__=='__main__': Manage=Manager () dic=manage.list ()deffoo (i): Dic[i]=100+IPrint(Dic.values ()) forIinchRange (10): P= Process (target=foo,args=(i,)) P.start ()Print(Dic.values ())
This idea is too mixed, but the teacher said that the process of data sharing is not much, n
Process Pool
The process pool maintains a sequence of processes that, when used, gets a process in the process pool, such as a process pool that is not available to use in the song process pool, and the program waits until the process pool has processes available
There are two methods of process pooling:
- Apply (Sync)
- Apply_async (asynchronous)
Co-process
The operation of threads and processes is triggered by the program interface, the final performer is the system, the operation of the process is the programmer
The meaning of the existence of the process; for multi-threaded applications, the CPU switches between threads by slicing, and thread switching takes time (save state, continue next). , only one thread is used, and a code block execution order is specified in one thread
Usage scenarios for the coprocessor: when there is a large number of operations in the program that do not require CPU (IO)
The old boy learns day11-1 process, process pool, and co-path