Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an import in python considered to be dynamic linking?

In the parlance of posix and general technical software development. Does an import of a purely python ( not cython or c compiled libraries ) module constitute a dynamic linking?

like image 969
Matt Joyce Avatar asked Nov 08 '16 17:11

Matt Joyce


People also ask

Is Python static or dynamic linking?

Python will always remain a dynamically typed language. However, PEP 484 introduced type hints, which make it possible to also do static type checking of Python code.

What is import in Python?

In Python, you use the import keyword to make code in one module available in another. Imports in Python are important for structuring your code effectively. Using imports properly will make you more productive, allowing you to reuse code while keeping your projects maintainable.

What is dynamic linking with example?

Dynamic linking means that the code for some external routines is located and loaded when the program is first run. When you compile a program that uses shared libraries, the shared libraries are dynamically linked to your program by default.


1 Answers

No, loading a pure-Python module is not considered a form of dynamic linking.

Traditional dynamic linking loads machine code into a new chunk of memory, and multiple executable processes can be given access (the dynamically linked library only needs to be loaded once, virtual memory takes care of the rest). The linker connects the executable and the dynamic library at runtime.

Loading a Python module, on the other hand, loads the bytecode for the modules into the Python process itself (Python will compile the source code if no bytecode cache is available at this time too). The loaded modules are not shared between processes. No translation has to take place, the result of running the bytecode produces new objects in the Python heap that all existing code in the interpreter can interact with.

No linker is involved in this process, no separate memory, to the OS there are no separate sections of memory to be managed as the module is simply part of the Python process memory.

like image 134
Martijn Pieters Avatar answered Oct 17 '22 07:10

Martijn Pieters