The old boy learns day11-1 process, process pool, and co-path

Source: Internet
Author: User

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

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.