[Twisted-Python] Problem: spawnProcess() never ending when installSignalHandlers=False

Matt Feifarek matt.feifarek at gmail.com
Fri Jun 10 18:43:13 EDT 2005


I'm using Twisted 1.3.0 on python2.4 on an Ubuntu-Hoary x86 Linux box.

I'm using twisted and spawnProcess() with a Queue structure to chain
processes that need to be called (specifically, imagemagick commands).
I use the "processEnded" event/method of t.i.p.ProcessProtocol to go
from one task to the next. Twisted shares a python process with a
multi-threaded web-app-kit (Webware) so it has to be run in a thread.

This worked well on other older versions of twisted and older versions
of python; also on linux. I've tracked down the problem to be twisted
itself (or my incorrect use of it) rather than my code. This example
illustrates it:

from twisted.internet import reactor
from twisted.internet.protocol import ProcessProtocol

class MyProt( ProcessProtocol ):
	def processEnded(self, reason):
		print "ended.", reason

executable = '/bin/touch'
args = ( '/tmp/foo.txt', )
args = (executable,) + tuple(args)

reactor.spawnProcess( MyProt(), executable, args )
reactor.callLater( 5, reactor.stop )


As is, this code never runs the "processEnded()" method of MyProt().
If I change the reactor.run() parameter to leave the signal handlers
on, it works.

Note that I need to leave the signal handlers turned off because I
can't run the reactor in the main thread; Webware needs that.

I also know that the subprocess is giving up its file descriptors; I
can see that if I put more print statements into MyProt(). And I know
that the subprocess is working; /tmp/foo.txt is there.

It seems that somehow the reactor is using signals to notice when a
process has ended; this makes a certain ammount of sense intuitively,
though I don't understand the nitty-gritty of processes and signals at
all. And more importantly, this has worked before on other
combinations of twisted/python.

Is this a bug? If so, has it been fixed? If not, what should I do to
detect when a spawned process is finished?

Thanks very much. Twisted rocks.

More information about the Twisted-Python mailing list