Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Natural laws have no pity.


devel / comp.lang.python / Re: Neither pdb or print() displays the bug

SubjectAuthor
o Re: Neither pdb or print() displays the bugAlan Gauld

1
Re: Neither pdb or print() displays the bug

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: alan.ga...@yahoo.co.uk (Alan Gauld)
Newsgroups: comp.lang.python
Subject: Re: Neither pdb or print() displays the bug
Date: Wed, 2 Jun 2021 00:10:33 +0100
Lines: 87
Message-ID: <mailman.494.1622591231.3087.python-list@python.org>
References: <alpine.LNX.2.20.2106011309580.25401@salmo.appl-ecosys.com>
<s96ep9$74n$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de gezjp0f6LOSqa1IU6J5sXw3UoIO52QM9dKQe8F5WsMpw==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '3.7': 0.03; 'def': 0.04;
'row': 0.05; 'debug': 0.07; 'sun,': 0.07; 'message-
id:@ciao.gmane.io': 0.09; 'module:': 0.09; 'prompt,': 0.09;
'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'subject:bug': 0.09; "can't": 0.14;
'assuming': 0.16; 'breakpoint': 0.16; 'builtin': 0.16; 'cameron':
0.16; 'conditional': 0.16; 'driven': 0.16; 'drops': 0.16;
'examine': 0.16; 'flickr': 0.16; 'from:addr:alan.gauld': 0.16;
'from:name:alan gauld': 0.16; 'init': 0.16; 'nothing.': 0.16;
'once.': 0.16; 'photo-blog': 0.16; 'received:116.202': 0.16;
'received:116.202.254': 0.16; 'received:116.202.254.214': 0.16;
'shepard': 0.16; 'simpson': 0.16; 'statements.': 0.16; 'stuck':
0.16; 'subject:() ': 0.16; 'triggered': 0.16; 'url-
ip:79.170.44.132/32': 0.16; 'url-ip:79.170.44/24': 0.16; 'url-
ip:79.170/16': 0.16; 'url-ip:79/8': 0.16; 'url:alan-g': 0.16;
'url:alan_gauld': 0.16; 'url:alangauldphotos': 0.16; 'wrote:':
0.16; 'python': 0.16; 'bug': 0.20; 'url:amazon': 0.20; "i've":
0.22; 'skip:_ 10': 0.23; "i'd": 0.23; 'to:addr:python-list': 0.23;
'code': 0.24; 'probably': 0.24; 'function': 0.28; 'single': 0.28;
'header:User-Agent:1': 0.31; 'there': 0.31; 'printed': 0.31;
'seem': 0.31; 'approach': 0.31; 'expect': 0.31; "i'm": 0.32;
'half': 0.32; 'objects': 0.32; 'window': 0.32; 'program': 0.33;
'using': 0.33; 'class': 0.33; 'header:In-Reply-To:1': 0.33;
'trying': 0.36; 'at:': 0.37; 'neither': 0.37; 'table': 0.37;
'(or': 0.37; 'author': 0.38; 'event': 0.38; "it's": 0.38; 'use':
0.38; 'called': 0.40; 'mentioned': 0.40; 'skip:q 10': 0.40;
'skip:w 10': 0.61; 'lot': 0.62; 'named': 0.63; 'follow': 0.63;
'above': 0.65; 'times': 0.66; 'events': 0.67; 'reach': 0.68;
'site': 0.69; 'lives': 0.69; 'url:author': 0.69; 'received:116':
0.71; 'waiting': 0.76; 'extra': 0.84; 'dozen': 0.84; 'skip:q 20':
0.95
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.8.1
In-Reply-To: <alpine.LNX.2.20.2106011309580.25401@salmo.appl-ecosys.com>
Content-Language: en-GB
X-Mailman-Approved-At: Tue, 01 Jun 2021 19:47:10 -0400
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: <s96ep9$74n$1@ciao.gmane.io>
X-Mailman-Original-References: <alpine.LNX.2.20.2106011309580.25401@salmo.appl-ecosys.com>
 by: Alan Gauld - Tue, 1 Jun 2021 23:10 UTC

On 01/06/2021 21:18, Rich Shepard wrote:
> On Sun, 30 May 2021, Cameron Simpson wrote:
>
>> I've only just started with pdb. As of Python 3.7 there's a builtin
>> function named breakpoint() which drops you into the debugger.

> I'm stuck with neither approach (pdb, print()) working.

> The activitytypes.py module:
>

> class ATMainWindow(qtw.QMainWindow):
>
> def __init__(self):
> super().__init__()
>
> # Model/View here.
> self.model = qts.QSqlTableModel(db=db) # for single table
> self.model.setTable('activitytypes')
> self.model.select()
>
> self.table = qtw.QTableView()
> self.table.setModel(self.model)
>
> self.setFixedSize(qtc.QSize(800, 600))

Assuming this is the line you want to examine set a beakpoint just above
it using the function that Cameron mentioned

(Or just set a breakpoint on the init() from pdb...

Trying to use step/next to debug an event driven application
is next to impossible. set breakpoints on the methods that
get triggered by events then generate the event to reach
the breakpoint.

Or, as in this case, on the init if you want to examine
objects as they are created.

As a general rule if you have to hit next/step more
than half a dozen times in a row you are probably making
extra work for yourself!

>> $/development/business_tracker/activitytypes.py(29)<module>()
> -> window = ATMainWindow()
> (Pdb) n
> False
>> $/development/business_tracker/activitytypes.py(30)<module>()
> -> window.show()
> (Pdb) n
>> $/development/business_tracker/activitytypes.py(32)<module>()
> -> app.exec_()
> (Pdb) n
> n
>> $/development/business_tracker/activitytypes.py(32)<module>()->None
> -> app.exec_()
> (Pdb) n

I'm not sure why you got that twice.
I'd expect you to only see it once.

>
> and there it sits. No (Pdb) prompt, nothing. And no printed statements.

It's waiting while the app runs and for you to terminate it.

> I'd appreciate recommendations on the process to find where the bug lives
> since I can't seem to find it with print() or line-by-line in pdb.

Use breakpoints, don't try to step through the code from the
beginning - there lies madness!

And for event handlers that get called a lot use conditional
breakpoints so that you only stop when you want to.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor