Problem with MySQLdb and mod_python

C

Cyril Bazin

Hi,

I installed an apache server with mod_python.
I have got a problem with the mysql connection of my python script.

In fact I tried this file :
---------------------------------
import os
os.environ["PYTHON_EGG_CACHE"] = "/tmp"
import MySQLdb
from mod_python import apache

def test(req):
db=MySQLdb.connect(user="xxx",passwd="xxx",host="xxx.xxx",db="xxx")
c = db.cursor()
requete = "SELECT * FROM document"
nbRows = c.execute(requete)
req.write("Result : %s"%repr(nbRows))
return apache.OK

---------------------------------

But it seems, after many tests, that the script stops at the
instruction : "c.execute(requete)"
The script works if I am logged on the server as "root" or "www". I use :
---------------------------------
Python 2.4.4 (#1, Oct 23 2006, 13:58:00)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2
Type "help", "copyright", "credits" or "license" for more information.'3.3.1'
---------------------------------

If someone has any information that can help me...

Thanks in advance,

Cyril BAZIN
 
L

Lawrence D'Oliveiro

Cyril Bazin said:
But it seems, after many tests, that the script stops at the
instruction : "c.execute(requete)"

What's the error message? This should be in Apache's error_log file.
 
C

Cyril Bazin

Thanks for your reply

The apache log contains lines like :

[Tue Jul 15 23:31:01 2008] [notice] mod_python (pid=11836,
interpreter='www.toto.fr'): Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:02 2008] [notice] child pid 11836 exit signal
Segmentation fault (11)
[Tue Jul 15 23:31:19 2008] [notice] mod_python (pid=11764,
interpreter='www.toto.fr'): Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:19 2008] [notice] child pid 11764 exit signal
Segmentation fault (11)

I think the problem comes from the MySQLdb module.
If I can't find another solution, I think I will downgrade the MySQLdb
version to 1.2.1

Cyril
 
J

John Nagle

Cyril said:
Thanks for your reply

The apache log contains lines like :

[Tue Jul 15 23:31:01 2008] [notice] mod_python (pid=11836,
interpreter='www.toto.fr'): Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:02 2008] [notice] child pid 11836 exit signal
Segmentation fault (11)
[Tue Jul 15 23:31:19 2008] [notice] mod_python (pid=11764,
interpreter='www.toto.fr'): Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:19 2008] [notice] child pid 11764 exit signal
Segmentation fault (11)

I think the problem comes from the MySQLdb module.
If I can't find another solution, I think I will downgrade the MySQLdb
version to 1.2.1

Sounds like version hell. mod_python and MySQLdb have to be
compiled with exactly the same compiler for this to work.

mod_python is usually troublesome. Python doesn't really have
quite enough isolation to run multiple unrelated instances reliably.
We use FCGI, which has the isolation of CGI but doesn't reload the
application for every transaction. Also, it's easier to debug if
CPython is crashing.

John Nagle
 
G

Graham Dumpleton

Cyril said:
Thanks for your reply
The apache log contains lines like :
[Tue Jul 15 23:31:01 2008] [notice]mod_python(pid=11836,
interpreter='www.toto.fr'):Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:02 2008] [notice] child pid 11836 exit signal
Segmentation fault (11)
[Tue Jul 15 23:31:19 2008] [notice]mod_python(pid=11764,
interpreter='www.toto.fr'):Importing module
'/usr/local/apache2/htdocs/intranet/courrier/test.py'
[Tue Jul 15 23:31:19 2008] [notice] child pid 11764 exit signal
Segmentation fault (11)
I think the problem comes from the MySQLdb module.
If I can't find another solution, I think I will downgrade the MySQLdb
version to 1.2.1

    Sounds like version hell.  mod_python and MySQLdb have to be
compiled with exactly the same compiler for this to work.

Use of compatible compilers applies to anything you want to use
together. This is nothing specific to mod_python, so this comment is a
bit misleading. These days with with GNU C everywhere, it is hardly
and issue, and was usually only an issue with C++ code and not C code
anyway.
   mod_python is usually troublesome.   Python doesn't really have
quite enough isolation to run multiple unrelated instances reliably.

The isolation issue is nothing to do with Python itself. Isolation is
an issue in this case, but most likely comes about because the OP is
trying to use both PHP and mod_python together in the same Apache
instance.

In particular, the PHP package is likely loading a MySQL module and it
is linked against a different version of the MySQL client libraries
than what the Python MySQL package is wanting.

People like to blame mod_python for these problems, but it can equally
be attributed to PHP. In practice the reason it shows up as a
mod_python issue is that PHP tries to preload a lot of stuff and so
manages to load its version of shared libraries first. Python with its
lazy loading comes in second, and so conflicts will occur. If
mod_python preloaded stuff like PHP did and this was occurring before
PHP got a chance, it would be the other way around and mod_python
would work fine and PHP would instead be what crashes all the time.
We use FCGI, which has the isolation of CGI but doesn't reload the
application for every transaction.  Also, it's easier to debug if
CPython is crashing.

With the reason that FCGI works being that the processes, even if they
are spawned by Apache, use a fork/exec, thus meaning they have a clean
memory space when starting up.

In summary, look at what version of MySQL libraries are used by PHP
modules and ensure that Python MySQL module is compiled against the
same version.

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top