Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Three main shortcomings of Python language and their Solutions

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "three main shortcomings of Python language and their solutions". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the three main shortcomings of Python language and their solutions.

Missing point 1: Python multithreading and speed

The overall performance of Python is slow, and its limited threading and multiprocessing capacity are the main obstacles to its future development.

Python has long valued the ease of use of programming rather than runtime speed. When you accomplish so many performance-intensive tasks in Python by using high-speed external libraries written in C or C++, such as Numpy and Numba, you will find that Python values the ease of use of programming is also a good choice. But in spite of this, the out-of-the-box performance speed of Python still lags behind other languages, such as Nim and Julia, which have the same simple syntax, but can be compiled into machine code with higher performance advantages.

Python's inability to make full use of multi-core processors has been a long-standing problem. It does have threading capabilities, but its threading capabilities are limited to a single core. Although Python can use multiple processes, the results of scheduling and synchronizing these subprocesses are not always valid

Solution

There is currently no single, top-down solution to solve the performance problem of Python, but we have a series of measures to accelerate Python. For example:

Using the PyPy interpreter instead of the official interpreter, PyPy is able to compile Python code into machine code, which works best in code that uses only Python's native modules, but it can now be applied to popular libraries such as numpy, but it is always suitable for long-running services, not applications that can be packaged and taken away.

Cython,Cython can convert Python+C mixed-coded .pyx scripts into C code. The project was originally designed for scientific and numerical calculations, but it can be used in most cases.

Numba,Numba is similar to Cython in that it is mainly used in scientific computing.

Mypyc, which is still under development, converts code decorated with mypyc type decorators into C.

Optimized Python distributions, such as Intel's specially compiled version for special processors and their special mathematical operations. However, although it can significantly speed up part of the operation speed, it can not speed up the overall operation speed.

If you are a master, you can also try to get rid of GIL (Global interpreter Lock) the reason why Python multithreading is fake is because of the existence of GIL: it is used to ensure that Python can only have one thread running at a time. So in theory, if you get rid of GIL, you can do multi-threaded operations, which can improve performance.

There is also an ongoing project that can solve many speed problems, that is, refactoring the implementation of the Python internal C interface, a non-confusing interface can make many performance improvements possible.

Disadvantage 2: Python packaging and executable files

Even 30 years after the birth of Python, Python still does not have a good way to generate executable files (exe programs, etc.)

We can only solve it through third-party tools. And it's troublesome to use.

Solution

Pyinstaller can be packaged with many libraries like numpy, but it has to be consistent with these libraries, which is too painful. And it generates a larger program because it encapsulates all the contents of the import statement.

Another method is also being studied, which is that the PyOxidizer project uses the Ruth language to generate binaries embedded in Python, but it is still a long way from becoming a real solution.

Disadvantage 3: Python package management, project management

When you want to port a local complex Python project to the server, you know how painful Python project management is.

You need to constantly install project dependencies, which may still be dependent, just like Russian nesting dolls, wanting to eat the keyboard directly.

Solution

This kind of problem, of course, needs to be handled by the Python development team, and they need to provide a set of elegant migration tools.

But they have taken a few steps in this direction, and according to PEP 518 Python's build dependencies have been merged into the pyproject.toml file format (replacing setup.py, requirements.txt, setup.cfg, MANIFEST.in and, most recently, Pipfile).

Of course, it's not impossible to use the poetry dependency management tool, which can easily package the dependencies you need.

At this point, I believe you have a deeper understanding of the "three main shortcomings of the Python language and their solutions". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 215

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report