Entry
Debugging server Python scripts
Apr 10th, 2001 09:44
Engineer TCSI,
A handy thing is the ability to run a server Python script inside the
debugger. This can be done as follows.
If I have a module (unit) Xxx, and a function (or method) Yyy, first,
rename the real Yyy to be _Yyy. Then, write the following:
def Yyy(*args):
import pdb, sys
g = sys.modules['Xxx'].__dict__ # Set globals to be module Xxx
l = {'args' : args} # Make "args" visible to
pdb
pdb.run("res = apply(_Yyy, args)", g, l)
Then, run the TOM without the +w option. This will fire off pdb using
stdin and stdout. You can then step into the function _Yyy and debug at
will.
Submitted by storey Wed Feb 3 11:45:20 PST 1999
Additional (slightly different) approach:
To run an embedded pdb, you need to add a few lines. For example, for
the Test method of fmtoCard in Topo, you do:
def Test(*args):
import sys, pdb
g = sys.modules['Topo'].__dict__
l = {'args':args}
pdb.run("res = apply(fmtoCardMix.Test0, args)", g, l)
return l['res']
def Test0(self, ret)
# The test method being debugged.
...
g is the globals, so that this runs in the global space of the module
being debugged. This needs to be named the correct name for your
module.
l is the locals, to pass in the args, and get the result. The
invocation is done at global scope, not class scope, so you need to pass
the full name from the module scope, which is <Class>.<Method>, in this
case, fmtoCardMix.Test0.