On Thu, Mar 20, 2014 at 04:22:05PM +0100, Gerhard Schmidt wrote:
> I am running a Zope2 system with 64 Frontend Zope Server and one Backend
> ZEO for quite some time ( > 10 Years ) so i know quite a lot about ZODB
> and zeo. My Solution to the Problem is the folowing function pair.
> 
> def startZODBAwarThread(context, method, delay=0, args=None, kwargs=None):
>     if args == None :
>         args = ()
>     if kwargs == None :
>         kwargs = {}
>     db = context._p_jar._db
>     contextpath = resource_path(context).split('/')[1:]
>     meth = getattr(context, method, None)
>     if meth != None  and callable(meth) :
>         thread.start_new(initZODBAwarThread, (db, contextpath, method,
> delay, args, kwargs))
> 
> def initZODBAwarThread(db, contextpath, method, delay, args, kwargs):
>     time.sleep(delay)
>     connection = db.open()
>     rc = connection.root._root['app_root']

I would suggest

      rc = connection.root()['app_root']

because `_root`, as the name suggests, is a private implementation
detail, while root() is a public API method.

>     context = rc
>     while contextpath and contextpath[0] != '' :
>         context = context[contextpath.pop(0)]
>     import transaction
>     transaction.begin()
>     meth = getattr(context, method)
>     meth(*args, **kwargs)
>     transaction.commit()
>     connection.close()


Marius Gedminas
-- 
The planning fallacy is that people think they can plan, ha ha.
            -- Eliezer Yudkowsky,
               http://www.overcomingbias.com/2007/09/planning-fallac.html

Attachment: signature.asc
Description: Digital signature

Reply via email to