Python 不解释已更改的文件,使用过时的 .pyc
昨天使用 Google App Engine 用 python 进行开发时,它停止运行当前版本的脚本。 即使 .py 源已更改,它似乎也运行以前预编译的 .pyc,而不是执行最新版本。
错误消息实际上引用了最新来源中的正确行。除非该行的位置发生了变化,否则它会引用先前发生错误的位置的行。
删除 .pyc 文件会导致从当前版本重新创建它们。目前删除所有 .pycs 是一个糟糕的解决方法。
我怎样才能找到问题的根本原因?
Using the Google App Engine to develop in python yesterday it stopped running the current version of the script.
Instead of executing the most recent version it seems to run the previously pre-compiled .pyc even if the .py source was changed.
Error messages actually quotes the correct line from the most current source. Except if the position of the line changed, then it quotes the line which is in the place where the error occurred previously.
Deleting .pyc files causes them to be recreated from the current version. Deleting all .pycs is a poor workaround for now.
How can I get to the root cause of the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你检查过你的系统时钟吗?我相信 python 根据时间戳确定是使用 .pyc 还是 .py。如果您的系统时钟被推迟,那么它会将 .pyc 文件视为较新的文件,直到系统时钟赶上上次构建它们的时间。
Did you check your system clock? I believe python determine whether to use the .pyc or .py based on timestamps. If your system clock got pushed back, then it would see the .pyc files as newer until the system clock caught up to the last time they were built.
您是否在与编译它们的系统不同的系统上编辑 .py 文件?
如果 .py 文件的修改日期比 .pyc 文件的修改日期新,编译器将重新编译 .py 文件。
它选择使用 .pyc 文件这一事实表明您的 .py 文件具有较旧的修改日期。仅当您的 .py 文件在不同的系统上进行修改,然后将其复制到要使用的系统,并且编辑环境/系统的时钟设置在运行时环境/系统的时钟后面时,才有可能实现这一点。
Are you editing the .py files on a different system than where they are being compiled ?
The compiler recompiles the .py files if its modification date is newer than the modification date of the .pyc file.
The fact that it is picking the .pyc file for use points to the fact that your .py file has an older modification date. This is only possible if your .py file is being modified on a different system and then being copied to the one where it is to be used and the editing environment/system's clock is set behind the runtime enviroment/system's clock.
以下步骤暂时解决了该问题:
或者它甚至可以启动 GAEL 一次,然后关闭它。将备份的首选项文件放回原处,以避免重新
配置:事实证明,这暂时解决了这个问题。
奇怪的是,当从命令行运行应用程序服务器时,它可以工作,例如
The following steps solved the issue temporarily:
Alternatively it might even work starting GAEL once, closing it and putting your backed up preference files back into place as to avoid having to reconfigure.
Edit: Turns out that fixes it… temporarily. Not exactly a very easy issue to debug.
Weirdly enough it works when running the appserver from the command line, such as