How to debug python + curses? [was: RE: Applying winpdb_reborn]

Cameron Simpson cs at cskk.id.au
Sun May 30 18:07:21 EDT 2021


On 31May2021 07:46, Chris Angelico <rosuav at gmail.com> wrote:
>On Mon, May 31, 2021 at 7:03 AM Alan Gauld via Python-list
><python-list at python.org> wrote:
>> You are not alone. debugging curses is one of the biggest obstacles 
>> to its use. [...]
>
>Never had this problem with curses per se (partly because I've used it
>very little), but a more general technique for debugging things that
>don't have a "normal" console is to create one via a pipe or file. The
>easiest way is something like:
>
>log = open("logfile.txt", "w")
>print(f"At this point, {foo=}", file=log, flush=True)
[...]

Also untried, but should work:

Open another terminal, note its terminal device with the "tty" command.  
Start your programme like this:

    python ...... 2>/dev/tty-of-the-other-termina

Send debug statements to sys.stderr. They should show in the other 
window.

I'd also think one could do some kind of shuffle setting up curses to 
attach its display to another terminal, letting you use an interactive 
debugging in the invoking terminal. Haven't tried this yet.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list