[Twisted-Python] problem remotely calling mehod that returns a Deferred

Tim Nagels tim_nagels at hotmail.com
Thu May 22 06:24:42 EDT 2003


I'm having trouble remotely calling the userWelcome method...

it returns a deferred with some databaseinformation...
when I wanted to test to see how it handles delays...I used 
time.sleep(30)...

then it seems to lose the connection and throws: 
twisted.spread.pb.PBConnectionLost

i've tested it with 15, 10, 5 secs... and when I go below 5 secs it seems to 
work again...(as does removing the sleep line)

Any ideas where the connection could be lost, can't seem to locate it...
tnx

code:

class FtpServFactory(pb.Root, pb.Perspective):

   ....

    def remote_takeInfo(self, info):
        print " got info:", info
        print dir(info)
        print info.name
        print info.welcome
        #pond.countFrogs()
        return "safe and sound" # positive acknowledgement

    ....
    def testcallb(self, resultlist):
        print "executing callback"
        time.sleep(5)				####  if I let it sleep for less then 5 seconds, or 
I just remove the line
        return resultlist[0][0]			####  the value is returned correctly...

    def failtestc(self, resultlist):
        print "failing callback"
        return resultlist

    def perspective_userWelcome(self, user):
        root = self.service.factory.root
        print dir(self)
        self.dbpool = 
adbapi.ConnectionPool("MySQLdb",host="localhost",db="pythonftpserv",port=3306
                                            ,user="root",passwd="")

        self.db    = FtpDatabase(self.dbpool)
        deff = self.db.getDescription("TascAdmin")
        deff.addCallbacks(self.testcallb,self.failtestc)

        return deff

################################################

.....

def main():
    from FtpServer import FtpInfoClient  # so it's not __main__.CopyPond
    inf = FtpInfoClient.CopyInfo()
    inf.initData("Johnny", """/temp/test.tst""", 
"""2002-10-05""","""/temp""","You will find me another ...shrubbery!")

    reactor.callLater(5,reactor.stop)
    sender = Sender(inf)
    deferred = pb.getObjectAt("10.10.0.47", 8800, 50)
    deferred.addCallback(sender.got_obj)

    pb.connect("10.10.0.47", # host name
           8880, # port number
           "guest", # identity name
           "guest", # password
           "FtpServer.ftp", # service name
           "guest", # perspective name (usually same as identity)
           None, # client reference, used to initiate server->client calls
           50 # timeout of 30 seconds before connection gives up
           ).addCallbacks(connected, # what to do when we get connected
                          failure) # and what to do when we can't


    reactor.run()

def connected(perspective):
    deff = 
perspective.callRemote('userWelcome',"TascAdmin").addCallbacks(success, 
failure)
    deff.setTimeout(30)

def fail(des):
    print "failed miserably"

def gotdes(des):
    print "description "+desc

def success(welcome):
    print welcome
    #welcome.addCallbacks(gotdes,fail)
    #reactor.stop()

def failure(error):
    print error
    print dir(error)
    print "Failed to obtain quote.\n"
    #reactor.stop()

if __name__ == '__main__':
    main()


-----------
Aso

_________________________________________________________________






More information about the Twisted-Python mailing list