title: multiprocessing and garbage collection
body: <p>In py2.6+, the <code>multiprocessing</code> module offers a <code>Pool</code> class, so one can do:</p>
  
  <pre><code>class Volatile(object):
      def do_stuff(self, ...):
          pool = multiprocessing.Pool()
          return pool.imap(...)
  </code></pre>
  
  <p>However, with the standard Python implementation at 2.7.2, this approach soon leads to "IOError: [Errno 24] Too many open files". Apparently the <code>pool</code> object never gets garbage collected, so its processes never terminate, accumulating whatever descriptors are opened internally. I think this because the following works:</p>
  
  <pre><code>class Volatile(object):
      def do_stuff(self, ...):
          pool = multiprocessing.Pool()
          result = pool.map(...)
          pool.terminate()
          return result
  </code></pre>
  
  <p>I would like to keep the "lazy" iterator approach of <code>imap</code>; how does the garbage collector work in that case? How to fix the code?</p>