[Zope3-Users] Still trying to connect to ZODB from external

Florian Lindner mailinglists at xgm.de
Tue May 8 17:02:32 EDT 2007


Hello,
I have a function called by a scheduler. Since it operates outside of Zope 
context I need to create a connection to the ZODB in order to call a utility:

    db = getUtility(ZODB.interfaces.IDatabase)
    conn = db.open()
    root = conn.root().data['Application']
   
    zope.app.component.hooks.setSite(root["cs"])
    
    utils = getUtilitiesFor(INewsfeed)
    for i in utils:
        print "Utility called:", i[0]
        i[1].sendNotification()
   
    conn.close()

This produces errors like:

Unhandled error in Deferred:
Traceback (most recent call last):
  File "/home/florian/Zope3/src/twisted/internet/posixbase.py", line 220, in 
run
    self.mainLoop()
  File "/home/florian/Zope3/src/twisted/internet/posixbase.py", line 228, in 
mainLoop
    self.runUntilCurrent()
  File "/home/florian/Zope3/src/twisted/internet/base.py", line 561, in 
runUntilCurrent
    call.func(*call.args, **call.kw)
  File "/home/florian/Zope3/src/twisted/internet/task.py", line 108, in 
__call__
    d = defer.maybeDeferred(self.f, *self.a, **self.kw)
--- <exception caught here> ---
  File "/home/florian/Zope3/src/twisted/internet/defer.py", line 107, in 
maybeDeferred
    result = f(*args, **kw)
  File "/home/florian/Desktop/zope/lib/python/CS/centershock/centershock.py", 
line 34, in releaseRefreshEvent
    conn.close()
  File "/home/florian/Zope3/src/ZODB/Connection.py", line 268, in close
    raise ConnectionStateError("Cannot close a connection joined to "
ZODB.POSException.ConnectionStateError: Cannot close a connection joined to a 
transaction

What is the right way to do it?

Thanks,

Florian


More information about the Zope3-users mailing list