[Twisted-Python] pb and adabpi witn interaction...

Fredrik info at cleosan.com
Mon Aug 5 05:29:00 EDT 2002


Problem with returning the value to the pb-client using interaction...
the code will print out the "Nextid is (number)" on the server but it
wont return the value to the client.

/Fredrik

from twisted.enterprise import adbapi 
from twisted.spread import pb
from twisted.internet import app

def getNextId(conn, tableName): 
    sql = """SELECT NextId FROM DbSequence where SeqName = '%s' """%(tableName)
    print sql
    conn.execute(sql)
    return conn.fetchall()
 
class DefinedError(pb.Error):
    pass

class SimplePerspective(pb.Perspective):
    db = adbapi.ConnectionPool("MySQLdb", db='dbname', user="root") 

    def perspective_echo(self, tableName):
        print 'echoing',tableName
        return self.db.interaction(getNextId,self.gotNextId,None,tableName)  
        
        # _^_
        # this dont return any value to the client 
    

    def perspective_error(self):
        raise DefinedError("exception!")

    def gotNextId(self,resultlist): 
        nextid = resultlist[0][0]
        print "next id is %d ." % (nextid) 
        return nextid 
    
class SimpleService(pb.Service):
    def getPerspectiveNamed(self, name):
        p = SimplePerspective(name)
        p.setService(self)
        return p

if __name__ == '__main__':
    import pbecho
    appl = app.Application("pbecho")
    pbecho.SimpleService("pbecho",appl).getPerspectiveNamed("guest").makeIdentity("guest")
    appl.listenTCP(pb.portno, pb.BrokerFactory(pb.AuthRoot(appl)))
    appl.run()
    #appl.save("start")






More information about the Twisted-Python mailing list