[Twisted-Python] Callbacks, Looping, and Variable Binding

Justin Johnson justinjohnson at fastmail.fm
Thu Jul 31 13:13:28 EDT 2003


When I run the following code, everytime the callbacks to "onSuccess" get
called, "item" is bound to the last element in "list".  Obviously what I
want is to have "item" bound to the value it had when I added the
callback.  How does one handle looping constructs like this in Twisted?


def someFunc():
    deferreds = []

    def onSuccess(results):
       d = item.doSomethingElseThatReturnsDeferred()
       return d

    d = doSomethingThatReturnsDeferred()

    for item in list:
        d.addCallbacks(onSuccess, log.err)
        deferreds.append(d)

    return defer.DefferedList(deferreds)




More information about the Twisted-Python mailing list