[mod_python] Problem with mod_python 3.1.4 and PHP 4.3.4

Ville Silventoinen vsi at ebi.ac.uk
Fri Feb 3 11:06:10 EST 2006


Hi,

I have quite a strange problem with mod_python 3.1.4. I'm using Python 2.4.1 subprocess module to execute simple command, something like:

def handler(req):
     req.content_type = "text/plain"

     ofh = tempfile.TemporaryFile()
     efh = tempfile.TemporaryFile()
     finish = time() + 30

     p = subprocess.Popen("ps -fu w3nobody",
                          bufsize=1,
                          stdout=ofh,
                          stderr=efh,
                          shell=True,
                          close_fds=True)

     while p.poll() == None and time() < finish:
         sleep(0.1)

     result = p.poll()
     if result == None:
         req.write("Command did not finish in 30 seconds!")
     else:
         # write output, close filehandles ...
     return apache.OK


Normally this works fine. But our web server runs also a Wiki, which uses 
libphp4.so. As soon as someone uses the Wiki, the above mod_python module 
doesn't work, i.e., the command never finishes in 30 seconds. If I 
increase the timeout to 20 minutes, the HTTP request terminates after a 
while with "The document contains no data". I also tried without 
subprocess (as in Python Cookbook chapter 9.12, which uses popen2, fcntl 
and select), same problem.

I've overcome the problem by not using the subprocess.Popen.poll() method. 
If I use subprocess.Popen.wait(), it works every time, with or without PHP.
This doesn't allow me to use a timeout with commands, however, which 
sometimes can get stuck.

I've "googled" couple of days. I found this bug in Python related to 
threading and subprocess module:

http://mail.python.org/pipermail/python-bugs-list/2006-January/031663.html

I also found the problem with MySQL, mod_python and PHP:

http://www.modpython.org/FAQ/faqw.py?req=edit&file=faq02.013.htp

But I don't see how this could affect subprocess module and I don't use 
MySQL with Python. I also couldn't find any references to conflicting 
libraries between mod_python, Apache, Python or libphp4.so. I've fixed a 
problem earlier related to expat, so the Apache is using the same version 
as Python (I couldn't tell if PHP uses expat).

Our PHP is version 4.3.4, Apache is 2.0.54 running on Linux 2.4.21-27.0.1.ELsmp (CentOS release 3.4).

Any advice would be most welcome! mod_python has otherwise been working great!

Best regards,
Ville




More information about the Mod_python mailing list