[Twisted-Python] Need replacement for subprocess.call within a pyAMF method - any suggestions?

Read Roberts rroberts at adobe.com
Tue Nov 3 18:55:42 EST 2009

I am trying to use the twisted reactor as a basis for a Python server for a
Flex app, using pyAMF.  My problem is that one  of the server methods
requires me to run a series of command-line tools to complete parsing data
from a file into an XML object, with lots of Python processing on the
results of one command-line tool to provide the input to the next one. I
have been using  subprocess.call  to invoke the command-line tools, but
these intermittently - and frequently -  fail with an error "IOError: [Errno
4] Interrupted system call".

I do know that this was supposed to be fixed in twisted for Python 2.6, but
it doesn't seem to be. I have python 2.6.3 under Mac OSX 10.5.8, and twisted
8.2.0. Is there a work-around for this problem, or a better way to do this
with twisted? I do know that I can make a command-line call with
reactor.callLater, and that I can return a deferred from my server method,
but I don't see how to easily accomplish the chain of calls that I need,
short of breaking up my serverMethod1 into the several sequential parts, and
calling each from the result handler of the previous one. I'd rather not go
that route, as the logic of which command-line call gets made when is
actually quite complicated.

What I have now looks like (enormously simplified):
class MyPythonServer:

    def serverMethod1(self, dummyPost, inputFilePath):
        # Open inputFilePath, do stuff, save results to file2
        subprocess.call(["command1", "file2", "file3"])
        # Open file3, do stuff to the data, save results to file4
        subprocess.call(["command2", "file4", "file5"])
        # Open file5, convert data to a large string containing XML.
        return xmlString
- Read Roberts

More information about the Twisted-Python mailing list