[mod_python] Win32 threading issue

Geoff Talvola gtalvola at nameconnector.com
Tue May 29 14:04:15 EST 2001


I just wanted to confirm that I also get the same behavior on Windows -- if 
I stress out a simple script like the one below with multiple simultaneous 
requests, I get sporadic errors, just as Chris Trengove reported.

I'd be happy to help diagnose and fix the problem, but I know next to 
nothing about Apache and mod_python's internals.  I do have access to VC++ 
6.0 and I have successfully compiled the mod_python dll (for Python 2.1).

Where should I go from here?

>I have been testing the following script on Apache with mod_python (Apache
>1.13.17, mod_python 2.7.2, Windows 2000). I have been interested in testing
>the possible throughput of this (and more useful scripts), so I have
>another Python script which continually loads this "page".
>
>from mod_python import apache
>import thread
>
>def handler(req):
>     req.content_type = "text/plain"
>     req.send_http_header()
>     req.write("%d\n" % thread.get_ident())
>     return apache.OK
>
>When I run more than one copy of the driver script (in multiple consoles),
>I get behavior indicative of some threading problems. Specifically, some
>connections get "lost", the Apache error log reports various instances of
>"IOError: Write failed...", and I occassionally get an access violation
>inside Apache. Similarly, if I only run one copy of the driver script, and
>just keep hitting the refresh button in a browser, the browser
>occassionally returns TWO numbers, and sometimes reports an error in
>retrieving the data. Note that I have tested my driver program retrieving a
>simple text file, and everything works as expected, so it does not appear
>to be a problem with Apache. (The problem also goes away if I set
>ThreadPerChild to 1 in the Apache configuration.)
>
>I have also found that, if I comment out the req.write() statement in the
>handler, then there are no problems. From my examination of the
>implementation of the request object, I see that req_write() contains calls
>to Py_BEGIN_ALLOW_THREADS / Py_END_ALLOW_THREADS, whereas
>req_send_http_header() contains no such calls. This suggests to me that
>some thread switching is occurring inside req_write() which is messing with
>the state of the interpreter.
>
>I would be most grateful if anyone has any information to offer on this.
>
>Chris Trengove


--

- Geoff Talvola
   gtalvola at NameConnector.com



More information about the Mod_python mailing list