title: Python multiprocessing wrapper
body: <p>I have a simple <code>multiprocessing</code> wrapper. Which takes a function and runs it in parallel and get the data back. </p>
  
  <p>However, I seem to be hard-coding my arguments (see <code>apply()</code>) . I am not sure how I can pass a more dynamic argument list. </p>
  
  <p>Here is my code</p>
  
  <pre><code>import multiprocessing as mp                                                     
  import time                                                                      
  
  class MPWrap(object):                                                            
      def __init__(self,verbose=False):                                            
          self.a=mp.Pool(10)                                                       
          self.resultObj=[]                                                        
          self.verbose=verbose                                                     
  
      def apply(self,func,args):                                                   
          for i in args:                                                           
              self.resultObj.append(                                               
                      self.a.apply_async(func,kwds={'x':i})                        
                  )                                                                
  
      def status(self):                                                            
          incomplete_count = sum(1 for x in self.resultObj if not x.ready())       
          if self.verbose:                                                         
            s="todo %d/%d tasks"%(incomplete_count,len(self.resultObj))            
            print s                                                                
          return incomplete_count                                                  
  
      def get(self):                                                               
          return  [ i.get() for i in self.resultObj ]                              
  
      def __del__(self):                                                           
          self.a.close()                                                           
          self.a.join()                                                            
          print "Done..."                                                          
  
  
  
  def square(x):                                                                   
      time.sleep(x)                                                                
      return x*x                                                                   
  
  def main():                                                                      
      x=MPWrap()                                                                   
  
      x.apply(square,                                                              
              args=[1,2,3,4,5,6,7,8,9]                                             
              )                                                                    
      while x.status() is None:                                                    
          time.sleep(.5)                                                           
          if x.status()==0:break                                                   
      print x.get()  
  
  if __name__=="__main__":                                                                      x[1, 4, 9, 16, 25, 36, 49, 64, 81]
      main()         
  </code></pre>