title: How to terminate multiprocessing Pool processes?
body: <p>I'm working on a renderfarm, and I need my clients to be able to launch multiple instances of a renderer, without blocking so the client can receive new commands. I've got that working correctly, however I'm having trouble terminating the created processes.</p>
  <p>At the global level, I define my pool (so that I can access it from any function):</p>
  <pre><code>p = Pool(2)
  </code></pre>
  <p>I then call my renderer with apply_async:</p>
  <pre><code>for i in range(totalInstances):
      p.apply_async(render, (allRenderArgs[i],args[2]), callback=renderFinished)
  p.close()
  </code></pre>
  <p>That function finishes, launches the processes in the background, and waits for new commands. I've made a simple command that will kill the client and stop the renders:</p>
  <pre class="lang-py prettyprint-override"><code>def close():
      '''
          close this client instance
      '''
      tn.write (&quot;say &quot;+USER+&quot; is leaving the farm\r\n&quot;)
      try:
          p.terminate()
      except Exception,e:
          print str(e)
          sys.exit()
  </code></pre>
  <p>It doesn't seem to give an error (it would print the error), the python terminates but the background processes are still running. Can anyone recommend a better way of controlling these launched programs?</p>