2

I'm using the rich library for progress/status indicators as well as coloring the log output to more easily make sense of it at a glance.

To enable rich's formatting in PyCharm's pydev debugger, one has to enable "Emulate terminal in output console" in the run configuration.

This way, however, one can no longer engage with the debugger's REPL in the usual fashion. Is there a way to realize this whilst retaining rich output and status indicators?

Sample code:

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()

Visualization of REPL interactivity for clarity. Script on the left, debuggers at various points in the script on the right side: REPL interactivity is lost when debugging within PyCharm, but not in case of pdb

Version information:

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

Probably not relevant: Shell: bash 5.1.16 Kernel: 5.16.2-1-MANJARO DE: Plasma 5.23.5

jrbergen
  • 660
  • 5
  • 16
  • 2
    Have you already figured this out? I've been running into the very same problem. So you're not alone. – Hendrik Wiese Feb 14 '22 at 11:15
  • I haven't solved it yet, unfortunately. I've been running it with either the 'emulate terminal' option disabled, or in a separate terminal outside of PyCharm using IPython post-mortem debugmode, as referenced [in this SO thread](https://stackoverflow.com/questions/16867347/step-by-step-debugging-with-ipython) instead. – jrbergen Feb 14 '22 at 23:25

0 Answers0