[Twisted-Python] reactor.stop() and deferToThead
charnedn at muohio.edu
Fri May 29 08:52:19 EDT 2009
Python seems to intentionally make aborting threads nigh impossible. You're
probably way better off doing something akin to this:
print "stuff2 finished"
print "Don't need to stuff2"
Also iirc in Twisted you need to use callFromThread on reactor methods
rather than calling the reactor directly.
On Fri, 29 May 2009 14:22:43 +0200, Thomas Jakobsen
<thomas.jakobsen at alexandra.dk> wrote:
> 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,
> from twisted.internet.threads import deferToThread
> from twisted.internet import reactor
> def stuff1():
> print "stuff1 finished; stopping reactor"
> def stuff2():
> print "stuff2 finished"
> d1 = deferToThread(stuff1)
> d2 = deferToThread(stuff2)
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
More information about the Twisted-Python