Python multi-Process vs multithreading

Source: Internet
Author: User

Multitasking in two ways: multi-process and multi-threaded.

If you implement master-worker with multiple processes, the master process is master and the other process is Worker.

If the Master-worker is implemented with multithreading, the main thread is master, and the other threads are worker.

The biggest advantage of multi-process mode is the high stability, the disadvantage is that the creation of excessive cost of the thread switching consumption resources.

Compute-intensive tasks: Use a language like C for greater efficiency

IO-intensive tasks: Using scripting languages such as Python development is most efficient

Asynchronous Io,python language, a single-threaded asynchronous programming model called a co-process

The modern operating system has made great improvements to IO operations, with the biggest feature being the support for asynchronous IO. If you take advantage of the asynchronous IO support provided by the operating system, you can use a single-process single-threaded model to perform multitasking , a new model called the event-driven model , and Nginx is a Web server that supports asynchronous IO. It uses a single-process model on a single-core CPU to efficiently support multiple tasks. On multi-core CPUs, you can run multiple processes (the same number as the number of CPU cores) to take advantage of multicore CPUs. Because the total number of processes in the system is very limited, operating system scheduling is very efficient.

Using the asynchronous IO programming model to achieve multi-tasking is a major trend.

Python multi-Process vs multithreading

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.