[mod_python] Lifespan of objects

Antonio Rodriguez Antonio at Memora.com
Thu Aug 19 18:59:47 EDT 2004


> 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
>



More information about the Mod_python mailing list