Notes on Linux & Python & threads & Processes

Source: Internet
Author: User

Parallel processing of multiple tasks. In order to prevent blocking, we plan to use threads for processing, but the results are not satisfactory after actual tests (of course, it must be related to my familiarity with threads ), multiple processes are stable and reliable :)

PS: chrome opens a process for each tab to ensure security and stability.

I often see some comments on the Internet, such

In an early article on IBM developerworks, I demonstrated a simple and effective mode for implementing Linear Programming Using python. However, one drawback of this method is that it does not always improve the application.ProgramBecause the global interpreter lock (Gil) effectively limits the thread to one core. If you need to use all the cores in the computer, you usually need to use the fork operation to increase the speed.

 

From: http://www.ibm.com/developerworks/cn/aix/library/au-multiprocessing/

Due to the controversial Gil mechanism in Python, threads become a weakness of Python (compared with C/C ++ and Java ).

Additional reading: thread security and Gil in Python

 

In addition, it is said that in Linux, due to the kernel mechanism, the thread does not seem to be widely used by the process.

For the same task, in order to make full use of the CPU to increase the processing efficiency, if a program in Linux runs multiple threads, the number of threads is closely related to the number of CPUs. For example, a 4-core CPU with 1 core is assigned to the main thread, and three cores are left. Therefore, only three other threads are required. In Windows, a large number of threads are usually used to handle this problem. Er ...... My current understanding is as follows. I don't know if it's right or not, and the underlying reasons for the specific difference are not clear ~ _~

 

Python 2.6 introduces a new multi-process processing module multiprocessing.

I am not very familiar with it.

It seems that the botnets have been directly solved internally. This is quite human: D.

 

In addition, the test also found that the singleton mode is still effective in multiple threads.

Because the member variables are saved in the heap, the parameter variables are saved in the stack.

For threads, stacks are independent, while stacks are shared.

So ...... It should be like this ~

 

Well, that's all. please correct me if there are any mistakes :)

 

 

 

 

 

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.