Python’s three major drawbacks and their solutions
Python has been around for about three decades, but it has only in the past few years seen its popularity soar beyond that of languages other than Java and C. Overall, Python has been an excellent starting point for teaching, learning about programming, and software development, and it can be a valuable part of any technology stack.
Unfortunately, this popularity also exposes Python’s shortcomings, the most notable and well-known of which are three: computational performance, packaging and executable generation, and project management
Here are three of the drawbacks that Python programmers face, and the solutions Python and its third-party tool developers have suggested to overcome them.
Disadvantages: Python multithreading and speed
Python’s overall slow performance, limited threading and multiprocessing capabilities are major obstacles to its future growth.
Python has long valued ease of programming over runtime speed. When so many performance-intensive tasks are done in Python through high-speed external libraries such as Numpy and Numba written in C or C++, Python’s emphasis on ease of programming is also a good choice. Even so, Python’s out-of-the-box performance lags behind that of other languages, such as Nim and Julia, which have the same simple syntax but can be compiled into machine code with higher performance benefits.
Python’s inability to take full advantage of multicore processors has long been a problem. It does have threading capabilities, but its threading capabilities are limited to a single core. While Python can use multiple processes, the results of scheduling and synchronizing these child processes are not always efficient
The solution
There is no single, top-down, holistic solution to Python’s performance problems, but there are a number of initiatives to speed up Python. Such as:
- Using the PyPy interpreter instead of the official interpreter, PyPy is able to compile Python code into machine code. PyPy works best with code that only uses Python’s native modules, but it can now be used with popular libraries such as Numpy, but it will always be suitable for long-running services. Not an app that can be packed away.
- Cython, Cython can convert Python+C mixed. Pyx scripts into C code. The project was originally designed for science and numerical calculations, but it can be used in most situations.
- Numba, similar to Cython, is primarily used for scientific computing.
- Mypyc, a project still under development, converts code decorated with mypyC-type decorators to C.
- Optimized Python distributions, such as specially compiled versions developed by Intel for particular processors and their particular mathematical operations. But while it can significantly speed up some operations, it can’t speed up the whole thing.
If you’re a pro, you can also try getting rid of the GIL (global interpreter lock). Python’s multithreading is fake because of the GIL: it ensures that Only one thread runs Python at a time. So theoretically, if you get rid of the GIL, you can do multi-threading and improve performance.
There is also an ongoing project to address many of the speed improvements by refactoring Python’s internal C interface implementation, where a clean interface makes many performance improvements possible.
Disadvantage 2: Python packaging and executables
Even after 30 years, Python still doesn’t have a good way to generate executables (exe programs, etc.)
The solution
- Pyinstaller can package and use a lot of libraries like Numpy, but it has to be versionable with those libraries, which can be a pain. And it generates a larger program because it wraps all the contents of the import statement together.
- There is also the PyOxidizer project, which uses Rust to generate binaries embedded in Python, under development, but it is still a long way from becoming a real solution.
Disadvantages 3: Python package management, project management
You know how painful Python project management can be when you want to port a complex Python project locally to a server
The solution
- This is, of course, something the Python development team needs to do to provide an elegant set of migration tools.
- But they’re already a few steps in that direction, and according to PEP 518, Python’s build dependencies are merged into the Pyproject.toml file format (replacing setup.py, requirements.txt, setup.cfg, manifest.in, and the most recent addition, Pipfile)
- There is also a way to use the Poetry dependency management tool, which makes it easy to package all the dependencies you need together.
That’s the end of this article! If you find it rewarding, please click on it and let more friends see this article! If you have any other questions, leave a comment in the window below!
Pythondict.com
It’s not just a bible
Welcome to Python