[Twisted-Python] Threading examples...
wcmclen at hotmail.com
Tue Mar 23 17:58:20 EST 2004
So, now my example looks like this:
from twisted.internet import reactor
# run method in thread
reactor.callInThread(aSillyBlockingMethod, "2 seconds have passed")
It still just hangs... I have to go kill it from another window after
getting its pid from ps. Am I doing the reactor.stop thing correctly?
Basically, I have an application that talks via a http interface to a user
and I need to spawn off and do stuff from time to time. I'm still learning
how all the reactor eventloops and whatnot work. I ran into a problem where
I'm trying to run something via twisted.internet.protocol.ProcessProtocol
and serve its results up from within a reactor.listentTCP() page handler ...
but it blew up. So, I'm thinking that I could maybe just fork it off and
run that way. I've been trying to figure out how the reactors() work and
the threading and whatnot the last few days but am kind of finding little
help in the docs and google that is at my level of understanding... seems
most of the stuff is snippets and pieces that assume you already see the big
picture :-( Any help here is greatly appreciated ;-)
>From: Andrew Bennetts <andrew-twisted at puzzling.org>
>Reply-To: twisted-python at twistedmatrix.com
>To: twisted-python at twistedmatrix.com
>Subject: Re: [Twisted-Python] Threading examples...
>Date: Wed, 24 Mar 2004 09:30:13 +1100
>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
> > some a lockup at the end.
> > Here's the code I'm playing with, I pulled it straight from the
> > (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.
>Twisted-Python mailing list
>Twisted-Python at twistedmatrix.com
Is your PC infected? Get a FREE online computer virus scan from McAfee®
More information about the Twisted-Python