Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Mystics always hope that science will some day overtake them. -- Booth Tarkington


devel / comp.lang.python / Re: How to debug python + curses? [was: RE: Applying winpdb_reborn]

SubjectAuthor
o Re: How to debug python + curses? [was: RE: Applying winpdb_reborn]Chris Angelico

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

<mailman.443.1622411226.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13462&group=comp.lang.python#13462

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn]
Date: Mon, 31 May 2021 07:46:52 +1000
Lines: 43
Message-ID: <mailman.443.1622411226.3087.python-list@python.org>
References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net>
<s90t32$112e$1@ciao.gmane.io>
<CAPTjJmrrKa5hy=-b2gdWbqc_1fEitNnZ=cWeahmRGZEEgEVZHg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de cqq3xhIrkxtA9zs27I/biQGW6G9AN5npZEFGZXsRRbYg==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=kM94eznZ;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; '31,': 0.05;
'subject:python': 0.06; 'debug': 0.07; 'debugging': 0.07;
'(python': 0.09; 'alone.': 0.09; 'keen': 0.09; 'module.': 0.09;
'point,': 0.09; 'window.': 0.09; 'log': 0.12; 'problem': 0.15;
'%s"': 0.16; 'chrisa': 0.16; 'easiest': 0.16; 'from:addr:rosuav':
0.16; 'from:name:chris angelico': 0.16; 'gauld': 0.16; 'machine,':
0.16; 'pipe': 0.16; 'subject:debug': 0.16; 'wrote:': 0.16;
'python': 0.16; 'figure': 0.18; 'uses': 0.19; 'subject:How': 0.22;
"i've": 0.22; 'anyone': 0.23; 'to:addr:python-list': 0.23; 'code':
0.24; 'tried': 0.26; 'else': 0.27; 'but': 0.31; 'approach': 0.31;
'script': 0.32; "i'm": 0.32; 'python-list': 0.32;
'to:name:python': 0.32; 'window': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'program': 0.33; 'received:209.85.166':
0.33; 'header:In-Reply-To:1': 0.33; 'received:google.com': 0.34;
'year': 0.35; 'bar': 0.35; 'from:addr:gmail.com': 0.35; 'way':
0.37; 'received:209.85': 0.38; 'something': 0.38; 'received:209':
0.38; 'use': 0.38; 'main': 0.40; 'could': 0.40; 'completely':
0.60; 'skip:w 10': 0.61; 'here': 0.62; 'skip:o 10': 0.62; 'per':
0.64; 'your': 0.64; 'subject:]': 0.71; 'subject:skip:w 10': 0.77;
'2021': 0.84; 'biggest': 0.84; 'positioned': 0.84; 'retained':
0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=dcHL0zFJ+xmYB4s4jnuQ9Iha09wPc4wB//fXy425NQM=;
b=kM94eznZly4ArlDDzXU14Lyj1LVQGJKdEC4w8vJCAr6ZgMeMlvJNj5F6vvsrwcwWRL
/j2/Kb5eqQufazSjUq9YmuwWxyUj2AVLLfJrl5Rwlx49aj4SimVD/Si97MK9q0eq8dCT
bXnkO2u0ff+uEhiYUobx806TG619WICIKel6d7s7BALvzk0aMcCyhIGk9J2iQD7QJSe5
fe3OgFBf4JLqMBLdfkLZNpKSDSlCJXu4zkBFg0sX4HYbt7cR1TmM3/cRmgDzvw3dUs3e
b6DaeLpMbp6vOHip2gMTEtNUG14P5Xs9ErNVzrL3QOtqFSF3TBY3EzAG7L1F1Oc2O2Za
PlcQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=dcHL0zFJ+xmYB4s4jnuQ9Iha09wPc4wB//fXy425NQM=;
b=n8PIow+AmichIinDkGU2X/qSN2BNU2zHBZIlGn1QDHWZJgTWlHC+KO6zXRxLqoWv0I
ctZT3bqTB2Lg5D/XTKU7+v8KaTQUXeudrS/Nu216Ulo0ykLjWcNh2J25rxBpkdNetbe9
01+DFJvxDMPCiKpZ1JCKsCrF/wK733dlpxxZ1sQNG7wONuJRpCY2DaDMnSEvZ3TB7Zlm
auVkZ8jXiqgXLMn4zTixpEIcifFqOgzdCyyM+iCCY3MtQS2bYzGstIaJJjVbUQDPQifo
piq0pK0Zh67hfjOUeEUAuZQzKMUGeAXL2CVXCuQGQrdxv3ekJWCAibjRJhEc/bL1DxDx
m4FQ==
X-Gm-Message-State: AOAM532LputQ4OXnvLEqXFhKYGlRI0Q2GZfKie1dVs+VtC/Bw+EEQqmV
IMYgEBxHkDwF+i61b55yoJIF2q2NYsbHmSlfeDMjxw68
X-Google-Smtp-Source: ABdhPJy/mgtz+7S6o4tCxp897NSdF21o51mVukOu1aI7JMqsskysXbZLjMdKvI3oVdNuTIquMmfDJbskKOxWLYwvU+w=
X-Received: by 2002:a6b:fb0f:: with SMTP id h15mr14729132iog.24.1622411223534;
Sun, 30 May 2021 14:47:03 -0700 (PDT)
In-Reply-To: <s90t32$112e$1@ciao.gmane.io>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmrrKa5hy=-b2gdWbqc_1fEitNnZ=cWeahmRGZEEgEVZHg@mail.gmail.com>
X-Mailman-Original-References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> <s90t32$112e$1@ciao.gmane.io>
 by: Chris Angelico - Sun, 30 May 2021 21:46 UTC

On Mon, May 31, 2021 at 7:03 AM Alan Gauld via Python-list
<python-list@python.org> wrote:
>
> On 30/05/2021 18:26, pjfarley3@earthlink.net wrote:
> > I tried winpdb-reborn some time last year on my Win10 system (python 3.8.3
> > at that time), but could not figure out how to use it to debug a python
> > script that uses the curses module.
>
> You are not alone. debugging curses is one of the biggest obstacles to
> its use.
>
> My approach is to define a status line at the bottom of my program and
> write print statements into that window. Something like:
>
> def main(stdwin):
> appwin = curses.newwin(...) # LINES-1 high
> status = curses.newwin(...) # 1 line high positioned on bottom
> # more code here
> status.addstr(0,0, "Value of foo = %s" % foo)
>
> curses.wrapper(main)
>
> After debugging the status window can either be retained as an
> application status bar or removed and the main window
> enlarged by one line...
>
> If anyone else has found a better way to debug curses code I'm
> also keen to hear!
>

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)

Then, in a separate window - or even on a completely different
machine, via SSH or equivalent - "tail -F logfile.txt" will be your
console.

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor