[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.


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
    return conn.fetchall()
class DefinedError(pb.Error):

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)
        return p

if __name__ == '__main__':
    import pbecho
    appl = app.Application("pbecho")
    appl.listenTCP(pb.portno, pb.BrokerFactory(pb.AuthRoot(appl)))

More information about the Twisted-Python mailing list