[Twisted-Python] Please help with Deferreds

Tommi Virtanen tv at twistedmatrix.com
Sat Aug 24 13:05:30 MDT 2002


	Can anyone explain the behaviour of the
	following?

#!/usr/bin/python
import sys
from twisted.internet import defer, reactor
d=defer.Deferred()
d.callback(0)
d2=defer.Deferred()
d.addCallback(lambda x,d2=d2: d2)

# switch the comment sign on the next two and it'll
# print not 1 but a Deferred. Why?
#reactor.callLater(0, lambda d2=d2: d2.callback(1))
d2.callback(1)

d.addCallback(lambda x:sys.stdout.write(repr(x)+'\n'))
d.addBoth(lambda x:reactor.stop())
reactor.run()


-- 
tv@{{hq.yok.utu,havoc,gaeshido}.fi,{debian,wanderer}.org,stonesoft.com}
double a,b=4,c;main(){for(;++a<2e6;c-=(b=-b)/a++);printf("%f\n",c);}




More information about the Twisted-Python mailing list