[Twisted-Python] (no subject)
    kwhitesell at adelphia.net 
    kwhitesell at adelphia.net
       
    Sun Dec  4 06:17:55 MST 2005
    
    
  
Hi Frank,
Best that I can tell, it's not your various classes that need to be converted to deferreds, just your program that calls class1, or even class1 itself.
The bottom line is that _something_ higher up the calling stack needs to be aware that this is an asynchronous process - and that a deferred gets generated along the way. I believe it would be helpful if the originating function is coded for this.
	I'm not a Twisted guru, so there may be an easier way to do this - but as I see it...
I would be writing the classes to look more like the following:
    class1():
        def check1(data):
            perform test
            if test failed:
                return defer.succeed(False)
            return class2.check2(data):
    class2():
        def check2(data):
            perform test
            if test failed:
                return defer.succeed(False)
            return class3.check3(data):
    class3():
        def check3(data):
            perform test
            if test failed:
                return defer.succeed(False)
            aDeferred = avatar.callRemote(check4,data)
            return aDeferred
Then, my originating class (and possibly becomming a wrapper class if this is used in many places).
    class0():
       def check0(data):
           class1.check1(data).addCallback(afterCheck)
        def afterCheck(result):
            return result
This way, all the functions return a deferred back up to the calling program - but the only one that causes a delay is the call to check4.
Ken
    
    
More information about the Twisted-Python
mailing list