[Zope-dev] volatile state maintenance
Stuart 'Zen' Bishop
zen@cs.rmit.edu.au
Mon, 10 Apr 2000 09:38:47 +1000 (EST)
On Sun, 9 Apr 2000, Sam Gendler wrote:
> I made a python base class which opens the connection, but I get the
> following error from zope when it tries to pickle the object into the
> ZODB.
> I don't actually need the database connection itself to be in the ZODB,
> as it will not be open the next time zope restarts, anyway, but I would
> like it to remain resident in memory so that I can use it without
Sounds like you need to store the actual metakit connection handle in a
volatile attribute ('_v_myconnection' instead of just 'myconnection').
These attributes are not stored in the ZODB and destroyed if/when the
object is swapped out of the ZODB memory cache. Note that you will have
one connection per Zope thread. If metakit isn't thread safe, you will
need to store the connection as a package global or class attribute and
provide appropriate locking mechanisms.
The connection can be reopened whenever the class is loaded into memory
using your products __setstate__ method:
def _gethandle(self):
if self._v_handle is None or notvalid(self._v_handle):
self._v_handle = metakitconnect()
return self._v_handle
def __setstate__(self,state):
"Initialize on reload from ZODB"
self._v_handle = None
self._gethandle()
--
___
// Zen (alias Stuart Bishop) Work: zen@cs.rmit.edu.au
// E N Senior Systems Alchemist Play: zen@shangri-la.dropbear.id.au
//__ Computer Science, RMIT WWW: http://www.cs.rmit.edu.au/~zen