Python Advanced Programming

Source: Internet
Author: User

The Python Gil blocks python code from running on multiple CPUs at the same time. In order to achieve concurrency, we can use module development that is not restricted to Gil,

For compute-intensive programs, concurrency can be achieved using the multiprocessing module, and for I/O intensive programs, you can use multiprocessing You can also use threading or Concurrent.futures modules to implement concurrency.

Too close to the underlying concurrency API is prone to error, in order to avoid this, you can use the Python Quue and multiprocessing modules without explicit lock (explicit lock), which provides a highly encapsulated queue structure, On the other hand, concurrent.futures can also be used.

Enhanced performance:

Use the pypy JIT compiler to speed up python;

Using modules written in C, such as arrays and numpy, to process an array;

Use Cprofile to analyze performance bottlenecks;

For modules that have been implemented in the C/C + +, or any module that conforms to the language calling convention (c calling convention), they can be found from pypi.python.org;

The above modules can be used cTYPES module or third party Cython package to call C program Library when PyPI cannot find it;

Python Advanced Programming

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.