[Zope] keeping a python object alive across pageviews

Chris Withers chrisw at nipltd.com
Thu Aug 28 12:18:17 EDT 2003


Kirk Lowery wrote:

> Whenever an external method is used to call the search engine, the
> search engine then makes a database connection. Zope database adapters
> cannot be used here, since it is emdros -- not Zope -- that is
> managing the database.

You could look at implementing a DA for emdros then...

> When that external method completes, the
> connection is lost. The more frequently that method is used, the
> greater the performance hit because of the overhead of restablishing
> the connection.

Hmmm, could use module level python variables in your external method:

myconnection = []

def myMethod(self):
   global myconnection
   if not myconnection:
     # create connection
     myconnection.append(theConnection)
   conn = myconnection[0]

..but you may need to worr abotu thread safety if you do that.

> Zope database adapters could solve this problem, but that would mean
> reimplementing the entire search engine in python as a Zope product,
> which doesn't seem to be a practical solution.

Might be the best idea though...

> alive within the Zope process across pageviews?  How do we associate
> such a python object with a particular user session?

Use the browser_id as a key into a module-level dictionary of connection 
objects. Thread safety will be an issue, as will getting rid of old connections...

cheers,

Chris




More information about the Zope mailing list