[mod_python] Persist database conn, or pers. variables - where I put them ?

Sean Davis sdavis at sherlock.nci.nih.gov
Thu Sep 28 07:50:43 EDT 2006


Richard Lewis wrote:
> On Wednesday 27 September 2006 14:55, Sean Davis wrote:
>   
>> On Wednesday 27 September 2006 09:16, Fredrik Sandin wrote:
>>     
>>> I asked the same question some time ago:
>>> http://modpython.org/pipermail/mod_python/2006-August/021924.html
>>> Graham Dumpleton suggested to use XML-RPC.
>>>
>>> As far as I have understood mod_python, or actually Apache, was
>>> not designed to allow for object persistency.
>>>       
>> Is this actually true (at least the Apache part)?  Under mod_perl (I'm a
>> mod_python total newbie), object persistence can be accomplished in several
>> ways including global variables that remain in shared memory (but this is
>> only within a single child), a database, in an in-memory or on-disk cache,
>> or in a session (just an interface to a cache or database).  Depends on
>> your definition, but Apache, it seems to me, is absolutely suited to allow
>> object persistence.
>>
>>     
> Persistance is all right: you can use global variables as you suggested.
>
> The problem comes at tidying up time. Apache provides no method of performing 
> operations when the server shuts down. This is especially relevant with 
> things like open database connections 
Richard,

Thanks for the clarification. 

Under mod_perl, there is Apache::DBI that overrides the connect() method 
of the DBI module to allow reuse of connections (maintaining a 
persistent connection).  When the server process dies, the DESTROY() 
method is called and the connections are cleaned up.  Would this be 
treated differently under mod_python for some reason, if a database 
connection object had a destroy() method that included a disconnect?  I 
have to admit that I don't understand many of the intricacies, but it 
seems that if it can be done in perl under mod_perl, there is likely a 
way to do it under python and mod_python.

Sean


More information about the Mod_python mailing list