Re: Internet search engine

Guido.van.Rossum@cwi.nl
Tue, 28 Mar 1995 15:03:29 +0200

> THis is a real pb, isn't it ? Debugging cgi script is a pain !!
> The solutions proposed by Guido looks good.
> Does somebody developped a complete environnment to debug
> cgi scripts (I don't know what is a complete debugging
> environment, but I would love something which allow to test
> a script with http and points out where is the error !!)

In Python 1.1 and later there's a standard module "traceback" which
helps by printing a stack trace exactly like the interpreter does.
You could put this at the end of your scripts (the function "main()"
is the script's main function):

if __name__ == '__main__': # Only do this when run as a script
import sys, traceback # Be prepared!
try:
main()
except SystemError, sts: # main() called sys.exit(sts)
sys.exit(sts)
except:
print "\n<XMP>" # Turn off HTML parsing
traceback.print_exc() # Print stack trace

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>