Re: Dealing with lost database connections
Jacob Smullyan <[email protected]> Thu, 21 Jul 2005 22:37:25 -0400
| Newsgroups | gmane.comp.web.skunkweb |
|---|---|
| Message-ID | <[email protected]> |
You can use the same basic approach, in various ways. If you use a connection pool, override the onHandOut() method and use a custom pool (also look at the default implementation). Every time you the pool issues a connection it will perform a test, if you want it to. That may be more testing than you feel like doing. (Er, I haven't tested the pools much; I think there are a couple of tests in the suite, but I haven't banged on them heavily.) Or, you can, at any time you wish, test the connection as follows: if not mySelectTest(db.conn): del db.conn # proceed DBIBase.conn is a property. The connection it returns is stored in thread local storage; if you delete it, the connection is closed and the next time you access it, a new connection will be created for you. (And of course, a new connection will be created if you access it in a different thread -- don't try to bring a transaction across threads, it won't work!) In a web application, for instance, you might want to perform such a test at most once per request; it may not be once per transaction. I hope that helps! js On Fri, Jul 22, 2005 at 01:10:29AM +0100, Hamish Lawson wrote: > It is common to cut down on the cost of opening a database connection > for each request by opening the connection once and reusing it for > subsequent requests (assuming the application is being handled by some > long-running process). However if the database goes temporarily > offline (say for backing up) then the connection may become > invalidated. Before using PyDO I dealt with this by wrapping the > connection in a class that detects such invalidation and creates a new > connection as necessary. How is this situation dealt with when using > PyDO? Given that PyDO creates its own connections, it doesn't seem as > if I can use my previous approach. > > > Hamish Lawson > > > ------------------------------------------------------- > SF.Net email is sponsored by: Discover Easy Linux Migration Strategies > from IBM. Find simple to follow Roadmaps, straightforward articles, > informative Webcasts and more! Get everything you need to get up to > speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click > _______________________________________________ > Skunkweb-list mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/skunkweb-list > -- Jacob Smullyan
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFC4FvluqamFyFXXLIRAq+IAJ4g+XKTPP2dn9kukOCeI18G4C7QkgCeLfNw 14QaWTPukiLuq5wGCD6Iii8= =NQdm -----END PGP SIGNATURE-----