[mod_python] Lifespan of objects

Nick nick at dd.revealed.net
Fri Aug 20 10:12:42 EDT 2004


Try calling gc.collect() occasionally, assuming the connections can be 
collected.  Don't know if the db module keeps an internal list of 
connections or not.  If it does, then forcing garbage collection may not 
help.  The 3rd module that has a connection pool may be your only hope in 
that case.

Nick

Antonio Rodriguez wrote:

>> When I started playing with DB API stuff I thought that destruction
>> would close the connection, but it didn't seem to. I had to
>> specifically close them.
> 
> 
> How do you specifically close them especially when mod_python is 
> performing the module reload automatically? Is there some sort of unload 
> hook?
> 
> I can think that an alternative is to put all of the db connection code 
> in a dbmodule.py and then import from there for the script your working 
> on. Since this dbmodule.py will not change as you work on your code, its 
> global dict (and therefore your connection object) should stay in scope 
> the whole time (unless you change dbmodule.py).
> 
> Does this make sense?
> 
> AR
> 
> On Aug 19, 2004, at 5:47 PM, Nic Ferrier wrote:
> 
>> Svenne Krap <svenne at krap.dk> writes:
>>
>>> I don't realize how I am using a single connection in parallel.
>>>
>>> While running apache, it forks new processes if there are simultanious
>>> connections. Each of these should open exactly one connection and
>>> use that.
>>
>>
>> Sorry, I missed what mpm you were using.
>>
>>
>>> I thought, that my example was a simple connection pool (I never need
>>> more than one cursor open per process anyhow), if I am in error, please
>>> provide pointers to a good connection pool (I haven't been able to
>>> locate any through google. Just a mailing-list suggestion that resembles
>>> my solution).
>>>
>>> It seems however, when I modify the .py-file the amount of connections
>>> grow. Is my program "losing" connections when the module is reloaded
>>> ?
>>
>>
>> If you modify the .py I'm sure you'll lose them. The old instances
>> will go out of scope and not be closed.
>>
>> When I started playing with DB API stuff I thought that destruction
>> would close the connection, but it didn't seem to. I had to
>> specifically close them.
>>
>>
>> Nic
>> _______________________________________________
>> 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