[Twisted-Python] Threading examples...

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") 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? Thanks, -William _________________________________________________________________ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

The following snippet is the code I use and it works for my needs. Be careful with non-threadsafe code (db api, etc...) though. ========== from twisted.internet import threads threads.deferToThread(aSillyBlockingMethod, x).addCallback(\ writeRequestAndFinish, request) ========= I am using this in a twisted webserver that is why I am registering the writeRequestAndFinish methode to finish up on the render methode where I returned server.NOT_DONE_YET. But you can register any callback or no callback as well. _stephan On Tue, 23 Mar 2004 12:19:01 -0700, William McLendon <wcmclen@hotmail.com> 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")
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?
Thanks, -William
_________________________________________________________________ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

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.
participants (3)
-
Andrew Bennetts
-
stephan
-
William McLendon