<HTML>
<HEAD>
<TITLE>Re: [Twisted-Python] Need replacement for subprocess.call within a pyAMF method - any suggestions?</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:14pt'>Hello Jean-Paul ;<BR>
<BR>
Thank you very much! For my simply workflow, blocking during a reactor call is acceptable, and simply calling reactor.run with installSignalHandlers=False does allow subprocess.Popen to work. My application is working, and I can continue development – I was totally blocked until I had this problem solved.<BR>
<BR>
I have not yet learned how to use inlineCallbacks, and will study up in this, as in the long run, I would like to server side to be able to handle multiple calls.<BR>
<BR>
Much appreciated,<BR>
Read Roberts<BR>
<BR>
On 11/3/09 4:08 PM, "<a href="exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>" <<a href="exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:14pt'>On 3 Nov, 11:55 pm, <a href="rroberts@adobe.com">rroberts@adobe.com</a> wrote:<BR>
>I am trying to use the twisted reactor as a basis for a Python server<BR>
>for a<BR>
>Flex app, using pyAMF. My problem is that one of the server methods<BR>
>requires me to run a series of command-line tools to complete parsing<BR>
>data<BR>
>from a file into an XML object, with lots of Python processing on the<BR>
>results of one command-line tool to provide the input to the next one.<BR>
>I<BR>
>have been using subprocess.call to invoke the command-line tools, but<BR>
>these intermittently - and frequently - fail with an error "IOError:<BR>
>[Errno<BR>
>4] Interrupted system call".<BR>
><BR>
>I do know that this was supposed to be fixed in twisted for Python 2.6,<BR>
>but<BR>
>it doesn't seem to be.<BR>
<BR>
I'm not sure why you know this. I sure would be great if that were the<BR>
case, but it's not. More changes in Twisted are necessary to let things<BR>
like subprocess.call work properly alongside Twisted's process API.<BR>
>I have python 2.6.3 under Mac OSX 10.5.8, and twisted<BR>
>8.2.0. Is there a work-around for this problem, or a better way to do<BR>
>this<BR>
>with twisted? I do know that I can make a command-line call with<BR>
>reactor.callLater, and that I can return a deferred from my server<BR>
>method,<BR>
>but I don't see how to easily accomplish the chain of calls that I<BR>
>need,<BR>
>short of breaking up my serverMethod1 into the several sequential<BR>
>parts, and<BR>
>calling each from the result handler of the previous one. I'd rather<BR>
>not go<BR>
>that route, as the logic of which command-line call gets made when is<BR>
>actually quite complicated.<BR>
<BR>
Are you aware that this means your server will only be able to handle<BR>
one request at a time? If so and that's what you're shooting for, then<BR>
you can fix this easily, by passing False to reactor.run. This<BR>
disable's Twisted's own process support and lets things like<BR>
subprocess.call work (blockingly, of course).<BR>
>What I have now looks like (enormously simplified):<BR>
>class MyPythonServer:<BR>
><BR>
> def serverMethod1(self, dummyPost, inputFilePath):<BR>
> # Open inputFilePath, do stuff, save results to file2<BR>
> subprocess.call(["command1", "file2", "file3"])<BR>
> # Open file3, do stuff to the data, save results to file4<BR>
> subprocess.call(["command2", "file4", "file5"])<BR>
> # Open file5, convert data to a large string containing XML.<BR>
> return xmlString<BR>
<BR>
Of course, you can still have methods that look like this if you use<BR>
things like inlineCallbacks (which you can, since you said you're using<BR>
Python 2.6). That way you preserve the style you seem to prefer and<BR>
avoid blocking your server any time you need to launch a child process.<BR>
<BR>
Jean-Paul<BR>
<BR>
_______________________________________________<BR>
Twisted-Python mailing list<BR>
<a href="Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><BR>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE>
</BODY>
</HTML>