When are Python files cached bytecode (pyc) updated?

Sometimes I run unittest in a specific mode, pointing to make PYTHON_TEST=path_of_module_to_test test, and if this module path_of_module_to_test testimports some other python module that has been updated, the import made from this module will be taken from the updated py source file or from unupdated pyc, or whether there will be an import imported into a dependent pyc file?

+4
source share
1 answer

From PEP 3147 :

CPython compiles the 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 greatly improves the loading of Python modules faster because the compilation phase can be bypassed. When your source file is foo.py, CPython caches the byte code in the right foo.pyc next to the source.

If your source is changing; CPython will recompile and re-cache the bytecode.

Please note that the above is for Python 2.x. All this changed in Python 3.xin Python 3.2: PEP 3147: PYC Repository Directories

.. "CPython" , Python, , , https://www.python.org, ( ) .

+1

All Articles