I suspect you may want to use the Pool() and map functions instead:<div><br></div><div>def process_image(image):</div><div>   do stuff to a single image</div><div><br></div><div>p = multi.Pool()</div><div>images = <span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">glob.glob(DirImg + </span><span style="font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); color: rgb(31, 185, 20); ">&#39;*r.sdf&#39;</span><span class="Apple-style-span" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 13px; background-color: rgba(255, 255, 255, 0.917969); ">)</span></div>
<div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">results = p.map(process_image, images)</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br></font></div>
<div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">this just farms out each function call to processors as they become available.</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br>
</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">cheers,</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif">Chris Beaumont</font></div><div><font class="Apple-style-span" color="#222222" face="arial, sans-serif"><br>
</font><br><div class="gmail_quote">On Fri, Nov 4, 2011 at 11:51 AM, Chris Sontag <span dir="ltr">&lt;<a href="mailto:sontag@stsci.edu">sontag@stsci.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

  
    
  
  <div bgcolor="#FFFFFF" text="#330000">
    Hi Jean-Baptiste,<br>
    <br>
    I&#39;m not sure this code is doing what you want.  Each of NPROC
    subprocesses runs CatDistort(), which does some processing on EACH
    image in your queue.  So each image actually gets processed NPROC
    times (by every subprocess), is that your intention?  If not, send
    one image as the value for the args of CatDistort().<br>
    <br>
    Chris<div><div class="h5"><br>
    <br>
    On 11/4/11 10:45 AM, Jean-Baptiste Marquette wrote:
    </div></div><blockquote type="cite"><div><div class="h5">
      
      Dear Python gurus,
      <div><br>
      </div>
      <div>I&#39;m not sure to be on the right mailing list, but I have the
        following problem:</div>
      <div><br>
      </div>
      <div>I have this code ran from Eclipse/PyDev:</div>
      <div><br>
      </div>
      <div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="color:#3600fc">import</span>
          multiprocessing <span style="color:#3600fc">as</span> multi</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font color="#3600fc"><br>
          </font></div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font color="#3600fc">
            <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="color:#3600fc">def</span>
              CatDistort(queue):</div>
            <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    <span style="color:#3600fc">for</span> Image <span style="color:#3600fc">in</span>
              iter(queue.get, <span style="color:#1fb914">&#39;STOP&#39;</span>):</div>
            <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre-wrap"> </span>etc...</div>
            <div><br>
            </div>
          </font></div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">queue = multi.Queue()</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br>
        </div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="color:#3600fc">for</span> Image <span style="color:#3600fc">in</span> glob.glob(DirImg + <span style="color:#1fb914">&#39;*r.sdf&#39;</span>):</div>

        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    queue.put(Image)</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    <span style="color:#3600fc">print</span>
          os.path.basename(Image), <span style="color:#1fb914">&#39;queued&#39;</span></div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">queue.put(<span style="color:#1fb914">&#39;STOP&#39;</span>)</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br>
        </div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">Jobs = []</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="color:#3600fc">for</span> i <span style="color:#3600fc">in</span> range(NPROC):</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    proc= multi.Process(target=CatDistort,
          args=[queue])</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    Jobs.append(proc)</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    proc.start()</div>
        <p style="margin:0.0px 0.0px 0.0px 0.0px;font:11.0px Monaco;min-height:15.0px">    <br>
        </p>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="color:#3600fc">for</span> job <span style="color:#3600fc">in</span> Jobs:</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">    job.join(<span style="color:#8e0308">360</span>)</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;min-height:15px"><br>
        </div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;color:rgb(31, 185, 20)"><span style="color:#3600fc">print</span><span style="color:#000000"> </span>&#39;Process
          completed&#39;</div>
        <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px">exit(<span style="color:#8e0308">0</span>)</div>
      </div>
      <div><br>
      </div>
      <div>The target and the queue work well, but the process never
        terminates. In other words, the final print is never displayed.</div>
      <div><br>
      </div>
      <div>Any hint ?</div>
      <div>Thanks for your help,</div>
      <div><br>
      </div>
      <div>Cheers</div>
      <div>Jean-Baptiste</div>
      <div><br>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
AstroPy mailing list
<a href="mailto:AstroPy@scipy.org" target="_blank">AstroPy@scipy.org</a>
<a href="http://mail.scipy.org/mailman/listinfo/astropy" target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a>
</pre>
    </blockquote>
  </div>

<br>_______________________________________________<br>
AstroPy mailing list<br>
<a href="mailto:AstroPy@scipy.org">AstroPy@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/astropy" target="_blank">http://mail.scipy.org/mailman/listinfo/astropy</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>************************************<br>Chris Beaumont<br>Graduate Student<br>Institute for Astronomy<br>University of Hawaii at Manoa<br>2680 Woodlawn Drive<br>
Honolulu, HI 96822<br><a href="http://www.ifa.hawaii.edu/~beaumont">www.ifa.hawaii.edu/~beaumont</a><br>************************************<br>
</div>