[Twisted-Python] wired problem with deferreds

markus espenhain me at mocisoft.com
Sun Feb 3 14:41:47 EST 2008


im stuck with the following deferred construct - the problem is that cb2
is called with None instead of the expected argument

from twisted.internet import defer

cd = None

def req1():
    return defer.Deferred().addCallback(req2)

def req2(a):
    print 'req2', a
    global cd
    if not cd:
        cd = defer.Deferred().addCallback(req3)
    return cd

def req3(a):
    print 'req3', a
    return a

def cb1(a):
    print 'cb1', a
    return a

def cb2(a):
    print 'cb2', a
    return a

d1 = req1().addCallback(cb1)
d2 = req1().addCallback(cb2)


req2 X
req2 X
req3 S
cb1 S
cb2 None # <- ?

req1 fetches a mapping for given arguments - req2 tries to create an
object + additional resquests by the result of req1 - but these objects
should only be created once - so far i didn't find an acceptable
workaround for that - req3 applys some modifications but the problem
occurs also without the step in req3 

is there something i overlooked so that cb2 isn't called with the
required arg?


More information about the Twisted-Python mailing list