python中的导入是否被认为是动态链接? [英] Is an import in python considered to be dynamic linking?

查看:44
本文介绍了python中的导入是否被认为是动态链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用 posix 和通用技术软件开发的说法.纯 python(不是 cython 或 c 编译的库)模块的 import 是否构成动态链接?

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?

推荐答案

不,加载纯 Python 模块不被视为一种动态链接形式.

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.

另一方面,加载 Python 模块会将模块的字节码加载到 Python 进程本身中(如果此时也没有可用的字节码缓存,Python 将编译源代码).加载的模块在进程之间不共享.无需进行翻译,运行字节码的结果会在 Python 堆中生成新对象,解释器中的所有现有代码都可以与之交互.

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.

这个过程不涉及链接器,没有单独的内存,对于操作系统来说,没有单独的内存部分需要管理,因为模块只是 Python 进程内存的一部分.

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.

这篇关于python中的导入是否被认为是动态链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆