Start pdb directly from Clouseau
When starting zope from a console, with runzope or zopectl fg, you can enter a pdb prompt in the console directly from Clouseau.
But first you need to set replace_stdout to False instead of True in the sessions.py file in Clouseau. This means you will get stdout directed to your console (as is normal without Clouseau), instead of to the Clouseau session in your browser. So be aware of what's written to the console where you started zope.
After the change, restart zope. (Start it with runzope or zopectl fg).
Now enter the following in your clouseau prompt:
import pdb
pdb.run('<statement to step through>', {'context':context})
Maybe like this:
import pdb
pdb.run('context.portal_interface.getInterfacesOf(context)', {'context':context})
Now look at the console where you started zope - you should have a pdb prompt:
2007-07-09 14:39:09 INFO Products.Clouseau.sessions queue: put source: import pdb
2007-07-09 14:39:27 INFO Products.Clouseau.sessions queue: put source: pdb.run('context.portal_interface.getInterfacesOf(context)', {'context':context})
> <string>(1)?()
(Pdb)
Here pdb is debugging the actual statement you typed in the Clouseau prompt (the 'string'). Type 's' to step into the execution of the statement.
You may see something like the following:
(Pdb) s --Call-- > /usr/local/lib/zope-2.9/lib/python/ZODB/Connection.py(720)setstate() -> def setstate(self, obj): (Pdb)
There will be some method calls like this to step through, before you get to the getInterfacesOf method. You can use the pdb command return to quickly return from these calls. After a couple of returns, you should get something like this:
--Call--
> /usr/local/lib/zope-2.9/instances/instance1/Products/CMFPlone/InterfaceTool.py(57)getInterfacesOf()
-> def getInterfacesOf(self, object):
(Pdb) l
52 iface = resolveInterface(dotted_name)
53 nd = iface.namesAndDescriptions(all=all)
54 return [(n, d.getDoc()) for n, d in nd]
55
56 security.declarePublic('getInterfacesOf')
57 -> def getInterfacesOf(self, object):
58 """Returns the list of interfaces which are implemented by the object
59 """
60 impl = getImplements(object)
61 if impl:
62 if type(impl) in (ListType, TupleType):
(Pdb)
Now step through, inspect, do whatever you intended to do.
While your debug session is running, your Clouseau session will not be useful.
Make sure that you complete your debug session with a continue command, or by using the return command until you no longer have a pdb prompt. Closing Clouseau or stopping Zope while leaving your debug session open will leave the standard output of your shell redirected.

Author: