Python 缓存字节码 (pyc) 文件何时更新?

When do Python cached bytecode (pyc) files get updated?

有时我 运行 通过指向 make PYTHON_TEST=path_of_module_to_test test 对特定模块进行单元测试,如果此模块 path_of_module_to_test test 导入其他一些已更新的 python 模块,将导入done from this module 从更新的 py 源文件或未更新的 pyc 文件中获取,或者导入会导致更新依赖的 pyc 文件?

来自PEP 3147

CPython compiles its source code into "byte code", and for performance reasons, it caches this byte code on the file system whenever the source file has changes. This makes loading of Python modules much faster because the compilation phase can be bypassed. When your source file is foo.py , CPython caches the byte code in a foo.pyc file right next to the source.

如果您的来源发生变化; CPython 将重新编译并重新缓存字节码。

注意上面是Python 2.x。这一切都在 Python 3.x Python 3.2: PEP 3147: PYC Repository Directories

中发生了变化

注意: 当我们在这里提到 "CPython" 时,我们指的是您最有可能使用来自 https://www.python.org 的 Python 的实现] 因为这种行为(我相信)是特定于实现的。