突然,我看到来自 IPython 调试器 ipdb 的警告,表明我的代码已过时,但是在调试时编辑/保存代码是常见用例,因此此警告没有帮助。
*** WARNING: file <path-to-file.py> was edited, running stale code until the program is rerun
当我在
<path-to-file.py>
中使用以下内容作为调试断点时,会出现该消息。
from ipdb import set_trace
...
set_trace()
IPython 将在调试断点处停止,然后编辑/保存后
<path-to-file.py>
警告消息开始出现在调试器控制台中。 希望完全禁用此警告。
ipdb 0.13.13
ipython 8.28.0
我在 Python 3.12 和 3.13 上看到了相同的行为,如下代码的结果:
scriptFile = self.writeScriptFile(script)
exec(compile(script, scriptFile, 'exec'), d)
其中脚本包含
breakpoint
语句。
我在 writeScriptFile 中修复了以下问题:
mod_time = os.path.getmtime(path) # New
with open(path, encoding='utf-8', mode='w') as f: # Existing
f.write(script) # Existing
os.utime(path, (mod_time, mod_time)) # New
HTH