Problem with MySQLdb and mod_python

Discussion in 'Python' started by Cyril Bazin, Jul 15, 2008.

  1. Cyril Bazin

    Cyril Bazin Guest

    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.
    >>> import MySQLdb
    >>> MySQLdb.__version__

    '1.2.2'
    >>> import mod_python
    >>> mod_python.version

    '3.3.1'
    ---------------------------------

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

    Thanks in advance,

    Cyril BAZIN
     
    Cyril Bazin, Jul 15, 2008
    #1
    1. Advertising

  2. In message <>, Cyril Bazin
    wrote:

    > 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.
     
    Lawrence D'Oliveiro, Jul 17, 2008
    #2
    1. Advertising

  3. Cyril Bazin

    Cyril Bazin Guest

    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

    On Thu, Jul 17, 2008 at 7:27 AM, Lawrence D'Oliveiro
    <_zealand> wrote:
    > In message <>, Cyril Bazin
    > wrote:
    >
    >> 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.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
     
    Cyril Bazin, Jul 17, 2008
    #3
  4. Cyril Bazin

    John Nagle Guest

    Cyril Bazin wrote:
    > 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
     
    John Nagle, Jul 18, 2008
    #4
  5. On Jul 18, 3:28 pm, John Nagle <> wrote:
    > Cyril Bazin wrote:
    > > 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
     
    Graham Dumpleton, Jul 18, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug Farrell

    Problem with mod_python and 4Suite

    Doug Farrell, Aug 8, 2003, in forum: Python
    Replies:
    2
    Views:
    346
    Doug Farrell
    Aug 12, 2003
  2. ws Wang
    Replies:
    2
    Views:
    492
    ws Wang
    Nov 30, 2004
  3. scott

    Apache/mod_python & MySQLdb

    scott, Jan 13, 2005, in forum: Python
    Replies:
    0
    Views:
    301
    scott
    Jan 13, 2005
  4. exhuma.twn
    Replies:
    3
    Views:
    334
    exhuma.twn
    Mar 20, 2006
  5. blbmdsmith
    Replies:
    1
    Views:
    652
    Graham Dumpleton
    Dec 14, 2006
Loading...

Share This Page