Is an import in python considered to be dynamic linking?
Asked Answered
V

1

13

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?

Victorvictoria answered 8/11, 2016 at 17:1 Comment(4)
Also, would it be considered dynamic linking in regards to the LGPL? I believe it would be, but IANAL.Mudguard
Yes and no depending on the definition of "dynamic linking". In the usual sense no, dynamic linking is only about linking of compiled programs (e.g. ELF executables), not scripts.Rubadub
I am less interested in that, as I am sure there is an argument around whether LGPL means c style linking or something entirely different.Victorvictoria
How does the GPL static vs. dynamic linking rule apply to interpreted languages?Krongold
G
14

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.

Gangplank answered 8/11, 2016 at 17:16 Comment(6)
Thanks. by "Loading a Python module, on the other hand" in Python, do you mean import statement or __import__() builtin function, or both, as in #28232238 ?Supplicate
@Tim: both, the import statement uses the __import__() hook to do its work.Gangplank
Thanks. Are both import statement and __import__() function belonging to en.wikipedia.org/wiki/Dynamic_loading or en.wikipedia.org/wiki/Dynamic_linking? If neither, what are they belong to, or which one are they more close to?Supplicate
It is neither. Python is not using OS-level library sharing to load bytecode data. From the OS point of view, Python modules are just data files.Gangplank
Thanks. What if we generalize the concepts of dynamic loading and dynamic linking from OS to Python interpreter or virtual machine? Are both import statement and __import__() function belonging to generalized "dynamic loading" or generalized "dynamic linking"? If neither, what are they belong to, or which one are they more close to?Supplicate
@Supplicate what are you trying to get to here? You can’t compare those very specific techniques, period.Gangplank

© 2022 - 2024 — McMap. All rights reserved.