Re: PyDO2: How to handle DB restart?

Jacob Smullyan <[email protected]> Sat, 24 Jun 2006 10:00:19 -0400
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
On Sat, Jun 24, 2006 at 02:34:31PM +0200, Faber wrote:
> Hello,
> 
> I'm using PyDO2 with PostgreSQL in a web application, hosted by a thirdy 
> party provider, using a connection pool:
> 
> db_pool = ConnectionPool(
> 	max_poolsize=10,
> 	keep_poolsize=0,
> 	delay=0.2,
> 	retries=10
> )
> 
> Sometimes the hosting restarts the PostgreSQL server, and I get this 
> exception in my Python code (even *after* the server has been restarted):
> 
> "ProgrammingError: terminating connection due to administrator command
> server closed the connection unexpectedly
>         This probably means the server terminated abnormally
>         before or while processing the request."
> 
> How could I avoid this exception?

Hi Faber --

I believe you want to subclass ConnectionPool and override onHandOut()
to perform an additional test on the connection, such as performing a
fast test query (a la "SELECT 1").  If onHandOut() returns False
you'll get a new connection.

Or, if the overhead of these tests is disagreeable (one test per
commit), you might be able to stick a hook in your web framework to
test one connection at request cleanup and reinitialize the pool if it
has gone sour.  However, if you tend not to use many transactions
per request it is probably OK.

Cheers,

js


> 
> Thank you
> 
> -- 
> Faber
> http://faberbox.com/
> http://smarking.com/
> 
> We live in a society exquisitely dependent on science and technology,
> in which hardly anyone knows anything about science and technology. -- Carl 
> Sagan
> 
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Skunkweb-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/skunkweb-list
> 

-- 
Jacob Smullyan

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

_______________________________________________
Skunkweb-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skunkweb-list
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFEnUVzuqamFyFXXLIRAqlCAJ9/OV3d7i4gokGhKgUhEKYKWDQ+bACfShdE
a8LPvTD4RGuZX/YAx+mA/TM=
=jbgh
-----END PGP SIGNATURE-----