<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. &nbsp;My application is working, and I can continue development &#8211; I was totally blocked until I had this problem solved.<BR>
<BR>
I have not yet learned how to use inlineCallbacks, &nbsp;and will study up in this, as in the long run, I would like &nbsp;to server &nbsp;side to be able to handle multiple calls.<BR>
<BR>
Much appreciated,<BR>
&nbsp;&nbsp;Read Roberts<BR>
<BR>
On 11/3/09 4:08 PM, &quot;<a href="exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>&quot; &lt;<a href="exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>&gt; 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>
&gt;I am trying to use the twisted reactor as a basis for a Python server<BR>
&gt;for a<BR>
&gt;Flex app, using pyAMF. &nbsp;My problem is that one &nbsp;of the server methods<BR>
&gt;requires me to run a series of command-line tools to complete parsing<BR>
&gt;data<BR>
&gt;from a file into an XML object, with lots of Python processing on the<BR>
&gt;results of one command-line tool to provide the input to the next one.<BR>
&gt;I<BR>
&gt;have been using &nbsp;subprocess.call &nbsp;to invoke the command-line tools, but<BR>
&gt;these intermittently - and frequently - &nbsp;fail with an error &quot;IOError:<BR>
&gt;[Errno<BR>
&gt;4] Interrupted system call&quot;.<BR>
&gt;<BR>
&gt;I do know that this was supposed to be fixed in twisted for Python 2.6,<BR>
&gt;but<BR>
&gt;it doesn't seem to be.<BR>
<BR>
I'm not sure why you know this. &nbsp;I sure would be great if that were the<BR>
case, but it's not. &nbsp;More changes in Twisted are necessary to let things<BR>
like subprocess.call work properly alongside Twisted's process API.<BR>
&gt;I have python 2.6.3 under Mac OSX 10.5.8, and twisted<BR>
&gt;8.2.0. Is there a work-around for this problem, or a better way to do<BR>
&gt;this<BR>
&gt;with twisted? I do know that I can make a command-line call with<BR>
&gt;reactor.callLater, and that I can return a deferred from my server<BR>
&gt;method,<BR>
&gt;but I don't see how to easily accomplish the chain of calls that I<BR>
&gt;need,<BR>
&gt;short of breaking up my serverMethod1 into the several sequential<BR>
&gt;parts, and<BR>
&gt;calling each from the result handler of the previous one. I'd rather<BR>
&gt;not go<BR>
&gt;that route, as the logic of which command-line call gets made when is<BR>
&gt;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? &nbsp;If so and that's what you're shooting for, then<BR>
you can fix this easily, by passing False to reactor.run. &nbsp;This<BR>
disable's Twisted's own process support and lets things like<BR>
subprocess.call work (blockingly, of course).<BR>
&gt;What I have now looks like (enormously simplified):<BR>
&gt;class MyPythonServer:<BR>
&gt;<BR>
&gt; &nbsp;&nbsp;&nbsp;def serverMethod1(self, dummyPost, inputFilePath):<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Open inputFilePath, do stuff, save results to file2<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subprocess.call([&quot;command1&quot;, &quot;file2&quot;, &quot;file3&quot;])<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Open file3, do stuff to the data, save results to file4<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subprocess.call([&quot;command2&quot;, &quot;file4&quot;, &quot;file5&quot;])<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Open file5, convert data to a large string containing XML.<BR>
&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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). &nbsp;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>