python class not instantiated - ways to catch/debug?
Im having some trouble with a python module (webpy.session) and Ive narrowed the problem down to a class not being instantiated.
Is there a way I can catch this happening and log the reason/error to a log file?
p.s (Ive tried r开发者_Python百科unning it in the python console and it works without error there)
I use pdb
to debug this kind of thing.
For example, to debug the code you posted, I would add:
db = web.database(dbn='mysql', db='auth', user='root', pw='')
store = web.session.DBStore(db, 'sessions')
import pdb; pdb.set_trace() # BREAK <<<< this line
session = web.session.Session(app, store, initializer={})
Which would let me step into the function (using s
), see what's returned, etc.
Bonus tip, if you use vim: map <F8> oimport pdb; pdb.set_trace() # BREAK<esc>
精彩评论