简体   繁体   中英

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

有时我通过指向make PYTHON_TEST=path_of_module_to_test test来在特定模块上运行 unittest 并且如果这个模块path_of_module_to_test test导入了一些其他已更新的 python 模块,那么从这个模块导入完成将从更新的 py 源文件或未更新的源文件中获取pyc 文件,还是导入会导致更新依赖的 pyc 文件?

From 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.

If your source changes; CPython will recompile and re-cached the bytecode.

Note that the above is for Python 2.x . This all changed in Python 3.x in Python 3.2: PEP 3147: PYC Repository Directories

Note: When we refer to "CPython" here we are referring to the implementation of Python that you are most likely using from https://www.python.org as this behaviour ( I believe ) is implementation specific.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM