[Twisted-Python] stop conditions and deferToThread()

Tim Allen screwtape at froup.com
Wed Jun 10 05:43:21 MDT 2009


I'm not sure this is the problem you're facing, but...

On Wed, Jun 10, 2009 at 12:04:16PM +0200, Thomas Jakobsen wrote:
> import time
> from twisted.internet import reactor
> from twisted.internet.threads import deferToThread
> 
> running = True
> 
> def foo():
>    while running:
>        print "working"
>        time.sleep(1)
> 
> def bar():
     global running
>    time.sleep(3)
>    print "stopping"
>    running = False
> 
> d1 = deferToThread(foo)
> d2 = deferToThread(bar)
> 
> reactor.run()

...does that make things run better?




More information about the Twisted-Python mailing list