Neither pdb or print() displays the bug

Alan Gauld alan.gauld at yahoo.co.uk
Tue Jun 1 19:10:33 EDT 2021


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




More information about the Python-list mailing list