quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jack Diederich" <jack_dieder...@email.com>
Subject Prefork import solutions/problems
Date Sat, 21 Sep 2002 21:34:25 GMT
re: my previous modification mentioned here

There was also a couple more emails of discussion on the python-dev mailing list, but I can't
find a web archive of that list.

Below is a patch I cooked up in a few hours, it cores 99% of the time.
the global static python_imports gets corrupted.  These are created via ap_make_table with
the server mem pool.  They shouldn't get freed until server exit time .. but they do.  Specifically
the memory is freed sometime after the parent inits the tables and the children try to read
them.  Creating these tables with malloc() makes this work 100% of the time, but then that
[small] amount of memory only gets cleaned up at shutdown.  For some reason apache cleans
up the memory when we make two tables, but not for one (the existing python_imports).

General improvements even if you don't like the preforkimports
* get_interpreter_name() returns the name of the interpreter that should be used.
  This works even for the PythonImport directive, which is new.
  It is also used for the PythonPreforkImport directive, this routine being called or not
in prefork mode is the difference between coring and not, if it isn't called before the fork,
we don't core.  It allocates a couple strings with the server pool, but nothing fancy.

Most of the changes are just to move around routines so that they are defined after the functions
they call.  python_init() had to be moved towards the end because it depends on do_imports(),
which depends on get_interpreter_name(), etc.

The short files:
change your httpd.conf to include
PythonImport "child_test"
PythonPreforkImport "foo"

import child_test

import os, sys

def set_pid():
    global pid
    pid = os.getpid()
    sys.stderr.write("Hello dolly %d\n" % (pid));
    return None

def get_pid():
    global pid
    return pid

import child_test

def handler(req):

  req.write('parent pid is ' + str(child_test.get_pid()) + 'but my pid is ' + str(os.getpid()))

then add the following patch, edit src/Makefile opts to include -DWITH_PFIMP, install, and
try to access any .py file.  you will core.  As best as I can tell with gdb (it cores half
the time!) the python_imports global gets freed sometime before the children access it.

I'm attaching the patch, as its a context diff and about 20k (mostly line-shifted functions)

Sign-up for your own FREE Personalized E-mail at Mail.com

View raw message