[mod_python] Singleton Object

Graham Dumpleton graham.dumpleton at gmail.com
Thu Dec 13 04:03:57 EST 2007


On 13/12/2007, Tom Wells <drshade at gmail.com> wrote:
>
> On Dec 13, 2007 10:13 AM, Graham Dumpleton <graham.dumpleton at gmail.com>
> wrote:
> > If you expect state to be available in each Apache child process when
> > run on UNIX, you cant avoid having multiple distinct connections back
> > to the back end system to collect the data. Playing with the C API
> > post config hook isn't going to help you.
> >
> > If a connection from each Apache child process is okay, then use
> > PythonImport directive to import a module on process startup which
> > does any once of initialisation.
> >
>
> Hi Graham - thanks for the quick reply!
> Your response is what I expected (sharing of data between child processes),
> just wanted to confirm the my understanding with the experts. Thanks, the
> PythonImport is actually exactly what I need for the watchdog thread.
>
> However, it should be possible to share state between apache child processes
> by using something like memcached right?

Using memcached is certainly an option.

For a bit of information on sharing issues see:

  http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel

The only other away around it would be to not use mod_python specific
features and write your application as WSGI application instead. You
could then use mod_wsgi, with embedded mode used on Windows and on
UNIX systems use daemon mode with a single multitheaded daemon
processes.

You can compare how mod_wsgi is same/different to mod_python in
respect of process use at:

  http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading

Graham


More information about the Mod_python mailing list