[mod_python] Persistent web-service

Graham Dumpleton grahamd at dscpl.com.au
Wed Sep 14 23:22:11 EDT 2005


Although PythonImport can be used to trigger startup code, the bigger
issue may be which which mode you run Apache in, ie., "prefork",
"worker" with single process, "worker" with multiple processes etc.

If you use Apache in a mode whereby there are multiple child
subprocesses, you will not have all your preserved state of the service
in the same process. You would therefore still have to have an external
data store holding data which needs to be shared, use shared memory, or
tunnel all requests using some sort of messaging abstraction to a
distinct single process which holds all the state.

This is all made more complicated due to the fact that Apache can
decide to shutdown child subprocess under certain circumstances such
as when a certain number of requests has been handled.

Still using a separate backend service process or framework is still
probably preferable, with the handlers using XML-RPC or some other
messaging system mechanism to communicate with it. You still have the
issue of having to ensure the backend service is started, but then it
also means your backend service isn't really dependent on Apache and
you could use other means to communicate with it. Ie., Apache just
becomes one type of interface.

Graham


On 13/09/2005, at 10:37 AM, Lee Brown wrote:

> Greetings!
>
> The default behavior of mod_python is to create a new python 
> interpreter for
> each Apache vhost.  This interpreter is initialized on server startup 
> and
> persists until server shutdown/restart.  By using mod_python's 
> PythonImport
> statement in your Apache config file, you can have a python module 
> execute
> when the interpreter starts.  Put your startup initialization routines 
> and
> your per-request function calls in this module.
>
> Best Regards,
> Lee E. Brown
> (administrator at leebrown.org)
>
> -----Original Message-----
> From: mod_python-bounces at modpython.org
> [mailto:mod_python-bounces at modpython.org] On Behalf Of Doru-Catalin 
> Togea
> Sent: Monday, September 12, 2005 10:31 AM
> To: mod_python at modpython.org
> Subject: [mod_python] Persistent web-service
>
> Hi!
>
> I am not sure wheather I should use the word service or server (or 
> something
> else) in the following, so I will stick to "service".
>
> I have some C code which I need to call from mod_python in a 
> web-service
> implementation. I need a persistent web-service, meaning either that my
> service is started up when Apache starts, or at the first call made 
> for my
> service. What I need is to have some C-structs initialized and which 
> survive
> calls to my service, until Apache shuts down. If it wasn't for this 
> need of
> persistency I could use some simpler mechanisms like CGI.
>
> To put it another way, I need a CORBA-like server, only based on 
> Apache.
> In a CORBA implementation, the server keeps running and serves 
> requests from
> clients as they arrive, without losing state between calls.
>
> Any suggestions on how to go about this task using Apache and 
> mod_python?
>
> Thanks for helping,
> Catalin
>
>
>
> -- 
>
>          <<<< ================================== >>>>
>          <<     We are what we repeatedly do.      >>
>          <<  Excellence, therefore, is not an act  >>
>          <<             but a habit.               >>
>          <<<< ================================== >>>>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list