[Twisted-Python] Threading examples...

Andrew Bennetts andrew-twisted at puzzling.org
Tue Mar 23 15:30:13 MST 2004


On Tue, Mar 23, 2004 at 12:19:01PM -0700, William McLendon wrote:
> Hi,
> 
> I'm trying out some of the threading examples from the web and am getting 
> some a lockup at the end.
> 
> Here's the code I'm playing with, I pulled it straight from the examples:
> 
> (source: 
> http://twisted.sourceforge.net/TwistedDocs-1.2.0/howto/threading.html)
> 
> 
> #!/usr/bin/env python
> import time
> from twisted.internet import reactor
> 
> def aSillyBlockingMethod(x):
>    import time
>    time.sleep(2)
>    print x
> 
> # run method in thread
> reactor.callInThread(aSillyBlockingMethod, "2 seconds have passed")

This example doesn't call to reactor.stop(), so it never stops.  Put a call
to "reactor.callFromThread(reactor.stop)" after the print statement, for
example, and it should shutdown cleanly.

> Is there something I need to do that will make the thread go away?  Are 
> there some more examples of threading in Twisted-Python available?

The only example I can think of is the implementation of
twisted.enterprise.adbapi, which presents an asynchronous interface to
blocking DB-API modules by running it in threads.

-Andrew.





More information about the Twisted-Python mailing list