[Twisted-Python] simple spawnProcess

jmbenski at micron.com jmbenski at micron.com
Wed Aug 10 18:36:32 EDT 2005

Ok, thanks.  I got it working.  I was just thinking of it in reverse.  All the google hits I came up with had someone talking about running the Qt and Twisted threads separately.  Apparently that is a good way to run in circles for awhile.

Thanks for the help.

-----Original Message-----
From: twisted-python-bounces at twistedmatrix.com [mailto:twisted-python-bounces at twistedmatrix.com] On Behalf Of glyph at divmod.com
Sent: Wednesday, August 10, 2005 2:38 PM
To: Twisted general discussion
Subject: RE: [Twisted-Python] simple spawnProcess

On Wed, 10 Aug 2005 08:53:48 -0600, jmbenski at micron.com wrote:
>Ok, obviously I'm missing something in the API.
>When I call reactor.run(), my main thread is stuck in the loop.  I tried to set up my code in a thread to get around this.

That is rather the point.  Using threads to "get around this" will break Twisted.  Threads are not supported for most APIs, and as JP said, they are what is breaking your program.

>    ##At some unknown point in the future I might need to issue commands

You are correct that your program will never get there.  Code after run() is not a place that your program should really ever *expect* to get.

If you need to run some code 'in the future', see reactor.callLater.  In general though, you will have to issue commands to your spawned process in response to some event.  Was it a button click?  Use Twisted's integration with a toolkit (such as GTK or Qt).  Was it a network request?  Set up a ProtocolFactory with a reference to your spawned process, or set up one that spawns processes itself when network connections are made.

There are lots of events which can potentially hpppen while the main loop is running.  Think of your program as a series of responses to those things, and the bit before reactor.run() as simply the set-up to make sure appropriate events get caught (your initial callLater to set up a timed loop, or a listenTCP to connect your program to the network) rather than as the program in its entirety.

Twisted-Python mailing list
Twisted-Python at twistedmatrix.com

More information about the Twisted-Python mailing list