1

我正在使用该rich库作为进度/状态指示器,并为日志输出着色,以便一目了然地理解它。

要在 PyCharm 的调试器中启用丰富的格式pydev,必须在运行配置中启用“在输出控制台中模拟终端”。

然而,这样一来,人们就不能再以通常的方式使用调试器的 REPL。有没有办法在保留丰富的输出和状态指标的同时实现这一点?

示例代码:

from rich.console import Console
from rich import pretty

if __name__ == '__main__':

    console = Console()
    pretty.install()
    status = console.status("Initializing...", speed=.2)
    status.start()

    # I would like to to have an interactive debugging session below,
    # with PyCharms's "Emulate terminal in output console" enabled.
    # However, it seems that one can no longer inspect local variables
    # in this case.
    print("IDE Breakpoint")

    # If we stop the status update, this still results in a non-interactive
    # session within PyCharm's debugger
    status.stop()
    print("IDE Breakpoint")
    status.start()

    # Running python -m pdb main.py from a terminal outside the IDE,
    # we can type status.stop() to stop Rich's status display,
    # and even though our output is visually overwritten by the
    # status indicator each refresh, we can hit enter to be dropped
    # into the pdb session as usual, with access to local variables, etc.
    breakpoint()

为了清晰起见,REPL 交互性的可视化。左侧的脚本,右侧脚本中各个点的调试器: 在 PyCharm 中调试时,REPL 交互性会丢失,但在 pdb 的情况下不会

版本信息:

  • PyCharm Professional 2021.3.2 (Build #PY-2136777.50)
  • rich 11.0.0
  • Python 3.9.9 and 3.10.1

可能不相关: 外壳:bash 5.1.16 内核:5.16.2-1-MANJARO DE:Plasma 5.23.5

4

0 回答 0