title: Python3 Pool async processes | workers
body: <p>I am trying to use 4 processes for 4 async methods.</p>
  
  <p>Here is my code for 1 async method (x):</p>
  
  <pre><code>from multiprocessing import Pool
  import time
  
  def x(i):
       while(i &lt; 100):
            print(i)
            i += 1
            time.sleep(1)
  
  def finish(str):
       print("done!")
  
  if __name__ == "__main__":
       pool = Pool(processes=5)
       result = pool.apply_async(x, [0], callback=finish)
  
  print("start")
  </code></pre>
  
  <p>according to: <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.JoinableQueue" rel="nofollow">https://docs.python.org/2/library/multiprocessing.html#multiprocessing.JoinableQueue</a>
  the parameter processes in Pool is the number of workers.</p>
  
  <p>How can i use each of these workers?</p>
  
  <p>EDIT: my ASYNC class</p>
  
  <pre><code>from multiprocessing import Pool
  import time
  
  class ASYNC(object):
      def __init__(self, THREADS=[]):
          print('do')
          pool = Pool(processes=len(THREADS))
          self.THREAD_POOL = {}
          thread_index = 0
          for thread_ in THREADS:
              self.THREAD_POOL[thread_index] = {
                  'thread': thread_['thread'],
                  'args': thread_['args'],
                  'callback': thread_['callback']
              }
              pool.apply_async(self.run, [thread_index], callback=thread_['callback'])
              self.THREAD_POOL[thread_index]['running'] = True
              thread_index += 1
      def run(self, thread_index):
          print('enter')
          while(self.THREAD_POOL[thread_index]['running']):
              print("loop")
              self.THREAD_POOL[thread_index]['thread'](self.THREAD_POOL[thread_index])
              time.sleep(1)
          self.THREAD_POOL[thread_index]['running'] = False
      def wait_for_finish(self):
          for pool in self.THREAD_POOL:
              while(self.THREAD_POOL[pool]['running']):
                  time.sleep(1)
  def x(pool):
      print(str(pool))
      pool['args'][0] += 1
  
  
  def y(str):
      print("done")
  
  A = ASYNC([{'thread': x, 'args':[10], 'callback':y}])
  
  print("start")
  A.wait_for_finish()
  </code></pre>