I hope you guys do not get upset, with all the stuff I'm throwing at you. I
only want Quixote (and SCGI) to become as good as possible. :^)
First, a small remark: the docstring for Publisher.setup_logs at line #148
of publish.py is out of sync with the actual behavior. It should read
something like this:
"""
Open all log files specified in the config file. Reassign
sys.stderr to go to the error log, and sys.stdout to go to
the debug log.
"""
And now the meaty stuff. Just do this:
1) include the line
sys.stdout = sys.__stdout__
at the end of the constructor for your Publisher-descendant class in the
script that starts SCGI;
2) include the lines
import pdb
pdb.set_trace()
in the part of your code that you want to debug;
3) apply the attached patch to SCGI 0.5 ;
4) call the script with the new -D option, like this:
./startSCGI.py -D
and voilĂ , you get the pdb prompt inside your Quixote application through
SCGI! Is that neat or what? ;^)
--
"Python is the Beatles of programming languages."
Aaron K. Johnson on comp.lang.python
Nicola Larosa - nico@tekNico.net
--- quixote_handler.py Tue Jul 2 23:29:29 2002
+++ quixote_handler.py.new Fri Jan 31 12:19:27 2003
@@ -97,6 +97,7 @@
-F -- stay in foreground (don't fork)
-P -- PID filename
-l -- log filename
+ -D -- debug (implies -F, inactivates -P and -l)
-p -- TCP port to listen on
-u -- user id to run under
""" % sys.argv[0]
@@ -106,7 +107,7 @@
uid = "nobody"
port = 4000
try:
- opts, args = getopt.getopt(sys.argv[1:], 'FP:l:p:u:')
+ opts, args = getopt.getopt(sys.argv[1:], 'FP:l:Dp:u:')
except getopt.GetoptError, exc:
print >>sys.stderr, exc
print >>sys.stderr, usage
@@ -114,6 +115,8 @@
for o, v in opts:
if o == "-F":
nofork = 1
+ if o == "-D":
+ nofork = 2
elif o == "-P":
pidfilename = v
elif o == "-l":
@@ -123,10 +126,11 @@
elif o == "-u":
uid = v
- log = open(logfilename, "a", 1)
- os.dup2(log.fileno(), 1)
- os.dup2(log.fileno(), 2)
- os.close(0)
+ if nofork != 2:
+ log = open(logfilename, "a", 1)
+ os.dup2(log.fileno(), 1)
+ os.dup2(log.fileno(), 2)
+ os.close(0)
if os.getuid() == 0:
change_uid_gid(uid)