[mod_python] psp.parsestring() hangs httpd

Jason Pratt jason at jasonpratt.org
Mon Dec 27 16:59:41 EST 2004

At 12/27/2004 01:58 PM, Gregory (Grisha) Trubetskoy wrote:

>On Sun, 26 Dec 2004, Jason Pratt wrote:
>>def handler( req=None ):
>>        req.content_type = "text/html"
>>        exec psp.parsestring( "Hello World" )
>>        return apache.OK
>I wonder if it insists on a newline at the end. That'd still make it a 
>bug, of course.

Good thought, but that doesn't seem to be it.  I tried a bunch of crazy 
stuff like \n, \r\n, \000, and full length documents.  None of it works.

I learned some more, though.  The process is not actually hanging in 
parsestring().  parsestring() actually returns the correct code (and 
identical to what parse() returns).  The process hangs when exec is 
called.  The one exception is if you pass an empty string to parsestring(), 
in which case the httpd process dies immediately rather than hanging.  And 
that actually does happen in parsestring().

You can put additional code before the exec and that code will run 
(including a time.sleep(), so it's not a time-delayed reaction).  You can 
omit the exec and the process still hangs, so it's not as if the generated 
code is bad.  At first I thought it was dying as soon as control was 
getting back to apache (i.e. it died in exec because req.write() was being 
called).  Remarkably, though, it dies whenever any code is execed.  It 
hangs on exec "x = 1 + 1".  This doesn't make any sense to me.

I've got to believe that something in _psp_module_parsestring() is writing 
to memory it shouldn't, or leaving something behind that it shouldn't, but 
the code looks correct.  I'm guessing the empty string problem may be 
because the "code = PyString_FromString(parser->pycode.blob);" line isn't 
wrapped in a check as it is in _psp_module_parse().  But that doesn't 
explain the hanging problem.

Jason Pratt
jason at jasonpratt.org

More information about the Mod_python mailing list