-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
broken pyc files #41838
Comments
In a number of situations, the .pyc files can become "corrupted" in a subtle way: the co_filename attribute of the code objects it contains become wrong. This can occur if we move or rename directories, or if we access the same set of files from two different locations (e.g. over NFS). This corruption doesn't prevent the .pyc files from working, but the interpreter looses the reference to the source file. It causes trouble in tracebacks, in the inspect module, etc. A simple fix would be to use the following logic when importing a .py file: if there is a corresponding .pyc file, in addition to checking the timestamp, check the co_filename attribute of the loaded object. If it doesn't point to the original .py file, discard the code object and ignore the .pyc file. Alternatively, we could force all co_filenames to point to the .py file when loading the .pyc file. I'll write a patch for whichever alternative seems better. |
I fail to see the corruption. It is quite desirable and normal to only ship pyc files - that the file name they refer to is actually present is not a requirement at all. |
What I called "corruption" is the situation This situation causes the tracebacks and the |
This problem is reported quite often in the tracker, http://www.python.org/sf/1666807 I closed those bugs as duplicates of this one. The logging package is also affected: http://www.python.org/sf/1669498 |
If you ask me, I think that when the importing There are many other quirks caused by .pyc files |
Wouldn't your first solution be simpler? Changing all Discarding the compiled code when the file names don't |
Here is a patch that implements arigo's last suggestion. File Added: update_co_filename.diff |
It's an obscure detail, but I think that the It's overall a mess, so let's play it safe. |
If code objects grew a __module__ attribute (which functions already |
This is causing problems for me as well. The attached patch no longer
It'd be nice if it wasn't necessary to check to see if co_filename |
As Armin said, I think it's safer and simpler not to rewrite the pyc |
New version of the patch which doesn't rewrite pyc files attached. |
Committed to trunk and py3k, and backported to 2.6 and 3.0. Thanks! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: