<p>For a similar use case, we&#39;re using a combination of cooperator with defertoprocess.</p>
<p>I can explain more if anyone&#39;s interested. </p>
<div class="gmail_quote">Le 29 oct. 2011 00:41, &quot;Donal McMullan&quot; &lt;<a href="mailto:donal.mcmullan@gmail.com">donal.mcmullan@gmail.com</a>&gt; a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think twisted.internet.defer.DeferredSemaphore is designed for this. John Paul Calderone answers a similar question in detail:<br>
<a href="http://stackoverflow.com/questions/2861858/queue-remote-calls-to-a-python-twisted-perspective-broker" target="_blank">http://stackoverflow.com/questions/2861858/queue-remote-calls-to-a-python-twisted-perspective-broker</a><br>

<br>
Donal McMullan<br>
<br>
<br>
On 29/10/2011, at 11:21 AM, Daryl Herzmann wrote:<br>
<br>
&gt; Hi,<br>
&gt;<br>
&gt; I have an application that ingests data and does a reactor.spawnProcess()<br>
&gt; for each chunk of data (a product) to pass it as STDIN to a compiled binary<br>
&gt; and then I harvest the STDOUT. It has been working well, but I have an issue<br>
&gt; when my data rates get too high and the machine gets overloaded with spawned<br>
&gt; processes (I think) and starts running out of file descriptors (yes I can<br>
&gt; raise it :) causing all sorts of pain.  I&#39;m wondering about a mechanism to<br>
&gt; throttle the number of spawned processes going at one time?  It&#39;d be nice to<br>
&gt; only have 10 of these spawned processes going at any one time.  Thanks for<br>
&gt; your ideas :)<br>
&gt;<br>
&gt; daryl<br>
&gt;<br>
&gt; code snipet:<br>
&gt;<br>
&gt; class SHEFIT(protocol.ProcessProtocol):<br>
&gt;    def __init__(self, tp):<br>
&gt;        <a href="http://self.tp" target="_blank">self.tp</a> = tp<br>
&gt;        self.data = &quot;&quot;<br>
&gt;<br>
&gt;    def connectionMade(self):<br>
&gt;        self.transport.write( self.tp.raw )<br>
&gt;        self.transport.closeStdin()<br>
&gt;<br>
&gt;    def outReceived(self, data):<br>
&gt;        self.data = self.data + data<br>
&gt;<br>
&gt;    def errReceived(self, data):<br>
&gt;        print &quot;errReceived! with %d bytes!&quot; % len(data)<br>
&gt;        print data<br>
&gt;<br>
&gt;    def outConnectionLost(self):<br>
&gt;        really_process(<a href="http://self.tp" target="_blank">self.tp</a>, self.data)<br>
&gt;<br>
&gt; def got_product():<br>
&gt;    shef = SHEFIT( tp )<br>
&gt;    reactor.spawnProcess(shef, &quot;shefit&quot;, [&quot;shefit&quot;], {})<br>
&gt;<br>
&gt; def really_process(tp,data):<br>
&gt;    print &#39;Do some work&#39;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Twisted-Python mailing list<br>
&gt; <a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
&gt; <a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div>