[Twisted-Python] reactor.stop() and deferToThead

Thomas Jakobsen thomas.jakobsen at alexandra.dk
Fri May 29 06:22:43 MDT 2009


Hi

It seems that things being deferredToThread continue to run even
though reactor.stop() is called.

Output from the example below is:

stuff1 finished; stopping reactor
stuff2 finished

Is there a way to abort the remaining execution of stuff2 in this
case? It would be handy if, say, some exception happens in in stuff1
that causes the execution of the remaining stuff2 to be meaningless.

Kind regards,
Thomas

---------------------------------------------

from twisted.internet.threads import deferToThread
from twisted.internet import reactor

def stuff1():
    time.sleep(2)
    print "stuff1 finished; stopping reactor"
    reactor.stop()

def stuff2():
    time.sleep(4)
    print "stuff2 finished"

d1 = deferToThread(stuff1)
d2 = deferToThread(stuff2)

reactor.run()




More information about the Twisted-Python mailing list