[mod_python] Mod_python multiple apache mod_python interpreters communication

Graham Dumpleton graham.dumpleton at gmail.com
Sat Oct 13 19:01:45 EDT 2007


On 14/10/2007, Thimios Katsoulis <thkatsou at yahoo.gr> wrote:
> Hello
> I am looking for a way so that the multiple python interpreters that run my mod_python application,
> communicate between them.
> In more detail I want to raise some sort of event that can be dispatched among all apache mod_python instances, so they perform some action,
> such as removing a global variable which is - as I understand - visible inside each separate interpreter context.
> Any ideas?

You do understand that within one Apache child process there can be
multiple Python sub interpreters which may be running distinct
applications. Then, there can be multiple Apache child processes.
Thus, there are two levels of communication, between sub interpreters
within the one Apache child process and between named sub interpreters
within different Apache child processes.

For some general background reading and some of the issues around
this, you can find more in:

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

As to a solution, it depends on what you are really trying to do.

One solution is not to do too much in the Apache/mod_python processes
to begin with. Instead, use a backend server process to do the real
work and use XML-RPC to communicate with that process. That way the
data that may need to be changed is in one process and there is not
need to synchronise between multiple processes.

Another solution may be to use memcached and store data that has to be
common to multiple processes with it, so that updates to data from one
are automatically seen by another process. In other words, some form
of shared memory mechanism.

At the more complicated end, you could have each Apache/mod_python
process participate in a distributed messaging system network, where
each process is able to subscribe to messages distributed by a central
server and act on the published messages when they are received to
change the value of some locally cached state. Such a system which is
known to be able to work within Apache/mod_python and its rather
hostile environment whereby multiple sub interpreters are being used,
is OSE (http://ose.sourceforge.net).

Having said all that, what exactly are you trying to do?

Graham


More information about the Mod_python mailing list