You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何禁用ipdb调试时的代码过期警告?

禁用ipdb的代码过期警告

针对ipdb 0.13.13 + ipython 8.28.0版本中,调试时编辑代码触发的*** WARNING: file <path-to-file.py> was edited, running stale code until the program is rerun警告,可通过以下几种方式彻底禁用:

方法1:修改IPython全局配置

这是最彻底的全局解决方案:

  1. 生成IPython配置文件(若未生成过):
ipython profile create
  1. 打开配置文件(路径通常为~/.ipython/profile_default/ipython_config.py),添加或修改以下配置项:
c.InteractiveShell.warn_on_code_change = False

保存后,所有ipdb会话都会继承这个设置,不再弹出代码变更警告。

方法2:通过环境变量临时屏蔽

如果不想修改全局配置,可在启动调试脚本前设置环境变量:

  • Linux/macOS终端:
export IPYTHON_WARNINGS="ignore::UserWarning:ipython.core.interactiveshell"
python your_script.py
  • Windows命令行:
set IPYTHON_WARNINGS=ignore::UserWarning:ipython.core.interactiveshell
python your_script.py

方法3:在代码中临时关闭

仅针对当前脚本生效,在调用断点前添加以下代码:

from ipdb import set_trace
from ipython.core.interactiveshell import InteractiveShell

# 关闭代码变更警告
InteractiveShell.instance().warn_on_code_change = False

set_trace()

验证:设置完成后,调试过程中编辑并保存代码,控制台将不再显示该警告。

内容的提问来源于stack exchange,提问作者Russell Burdt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 07:37:02