Matt Joyce Matt Joyce - 1 month ago 5
Python Question

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?

Answer

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.