Show
Ignore:
Timestamp:
02/15/08 17:08:59 (2 years ago)
Author:
JensDiemer
Message:

FastCGI: besser debugging

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/index.fcgi

    r1413 r1415  
    1616    -You need the python package "flup": http://trac.saddi.com/flup 
    1717 
     18    Debugging help 
     19    ~~~~~~~~~~~~~~ 
     20    If you only see something like 
     21        - "FastCGI Unhandled Exception" 
     22        - "Internal Server Error" 
     23        - "Premature end of script headers" 
     24    try this: 
     25        - Set a LOGFILE 
     26        - use the runfastcgi() options: 
     27            daemonize="false" 
     28            maxrequests=1 
     29        - Use ./tests/server_tests/fastCGI_test.fcgi 
     30        - Try to turn on the flup traceback, see: 
     31            http://code.djangoproject.com/ticket/6610 
     32 
    1833    Last commit info: 
    1934    ~~~~~~~~~~~~~~~~~ 
     
    2540    :license: GNU GPL v3, see LICENSE.txt for more details. 
    2641""" 
    27 import sys, os 
     42import sys, os, time 
     43 
     44start_overall = time.time() 
    2845 
    2946# Logging 
     
    4158os.environ['DJANGO_SETTINGS_MODULE'] = "PyLucid.settings" 
    4259 
     60# Global variable for the last traceback: 
     61last_tb_info = None 
    4362 
    4463#______________________________________________________________________________ 
     
    5473    ) 
    5574    log = logging.debug 
    56     log("Logging started") 
     75    log("--- Logging started ---") 
    5776else: 
    5877    # No logging 
     
    83102        log("StdErrorHandler error: %s" % e) 
    84103 
    85  
    86104#______________________________________________________________________________ 
    87105 
     
    90108    """ Minimalistic WSGI app for debugging """ 
    91109    start_response('200 OK', [('Content-Type', 'text/html')]) 
    92     yield '<h1>FastCGI Traceback catch:</h1>' 
     110    yield '<h1>FastCGI Traceback catch</h1>' 
    93111 
     112    # Display the overall running time 
     113    yield 'overall time: %.2fsec' % (time.time() - start_overall) 
     114 
     115    # Display the last traceback 
     116    yield '<h2>last_tb_info:</h2>' 
    94117    try: 
    95         import traceback 
    96         yield "<pre>%s</pre>" % traceback.format_exc() 
     118        yield "<pre>%s</pre>" % last_tb_info 
    97119    except Exception, e: 
    98120        yield "Traceback error: %s" % e 
    99121 
     122    yield '<hr />' 
     123 
    100124    from cgi import escape 
    101     yield '<hr /><h1>FastCGI Environment</h1><table>' 
     125    yield '<h1>FastCGI Environment</h1><table>' 
    102126    for k, v in sorted(environ.items()): 
    103127        yield '<tr><th>%s</th><td>%s</td></tr>' % ( 
    104128            escape(repr(k)), escape(repr(v)) 
    105129        ) 
    106  
     130    yield '</table>' 
    107131 
    108132#______________________________________________________________________________ 
     
    135159        #method="prefork",  # prefork or threaded (default prefork) 
    136160        #daemonize="false", # Bool, whether to detach from terminal 
    137         maxrequests=1,     # number of requests a child handles before it is 
     161        #maxrequests=1,     # number of requests a child handles before it is 
    138162                            # killed and a new child is forked (0 = no limit) 
    139163        #maxspare=2,        # max number of spare processes/threads 
    140164        #maxchildren=2      # hard limit number of processes/threads 
     165        #debug=True,        # Not Implemented, see: 
     166                            # http://code.djangoproject.com/ticket/6610 
    141167    ) 
    142168except SystemExit, e: 
     
    144170except Exception, e: 
    145171    log("fastCGI error: %s" % e) 
     172    import sys, traceback 
     173    last_tb_info = traceback.format_exc() 
     174    log(last_tb_info) 
    146175    from flup.server.fcgi import WSGIServer 
    147176    WSGIServer(tb_catch_app).run()