I would like to understand what happens with the below 2 code snippets -
SNIPPET#1
from twisted.internet import threads, defer, reactor
def proc1(a):
while True:
print "Proc----------1"
def proc2(a):
while True:
print "Proc----------2"
def proc3(a):
while True:
print "Proc----------3"
d1 = threads.deferToThread(proc1)
d2 = threads.deferToThread(proc2)
d3 = threads.deferToThread(proc3)
reactor.run()
My understanding is all the threads run parallely and the output is => stdout of all the procs mixed
SNIPPER#2
from twisted.internet import threads, defer, reactor
def proc1(a):
while True:
print "Proc----------1"
def proc2(a):
while True:
print "Proc----------2"
def proc3(a):
while True:
print "Proc----------3"
d1 = defer.Deferred()
d2 = defer.Deferred()
d3 = defer.Deferred()
d1.addCallback(proc1)
d2.addCallback(proc2)
d3.addCallback(proc3)
d1.callback('a')
d2.callback('a')
d3.callback('a')
reactor.run()
And for this snippet - each deferred callback is triggered one after the other and as far as the output is concerned there will only proc1 stdouts pouring indefinitely.
Please correct me if I am wrong folks. So basically what i want to understand and confirm is Deferred objects are triggered one after the other whereas the deferToThread are run parallely as by the name thread.