title: Python multiprocessing Process ID
body: <p>I'm using multiprocessing.Pool too run different processes (e.g. 4 processes) and I need to ID each process so I can do different things in each process. </p>
  
  <p>As I have the pool running inside a while loop, for the first iteration I can know the ID of each process, however for the second and more iterations this ID changes or at least I can't find one property that seems to be the same for each process in all iterations. </p>
  
  <p>The relevant part of the code is as follows:</p>
  
  <pre><code>     while i &lt;= maxiter:
          print('\n' + 'Iteration: %r'%i + '\n')
  
          pool = mp.Pool(processes = numprocs)
  
          swarm = pool.map_async(partial(proxy, costf = costFunc, i=i),Swarm)
          pool.close()
          pool.join()
  
          Swarm = swarm.get()
  </code></pre>
  
  <p>I've tried with the following properties to properly ID the processes but it's not working for me:</p>
  
  <pre><code>print(mp.Process().name)
  print(mp.current_process().name)
  </code></pre>
  
  <p>With this the output is:</p>
  
  <pre><code>Iteration: 1
  
  Process-2:1
  Process-1:1
  ForkPoolWorker-1
  ForkPoolWorker-2
  Process-3:1
  ForkPoolWorker-3
  Process-2:2
  ForkPoolWorker-2
  Process-3:2
  Process-2:3
  ForkPoolWorker-3
  ForkPoolWorker-2
  Process-1:2
  ForkPoolWorker-1
  Process-4:1
  Process-3:3
  ForkPoolWorker-4
  ForkPoolWorker-3
  Process-2:4
  ForkPoolWorker-2
  
  Iteration: 2
  
  Process-5:1
  ForkPoolWorker-5
  Process-5:2
  Process-7:1
  ForkPoolWorker-7
  Process-6:1
  ForkPoolWorker-5
  ForkPoolWorker-6
  Process-5:3
  ForkPoolWorker-5
  Process-7:2
  ForkPoolWorker-7
  Process-5:4
  ForkPoolWorker-5
  Process-6:2
  ForkPoolWorker-6
  Process-7:3
  ForkPoolWorker-7
  Process-8:1
  ForkPoolWorker-8
  </code></pre>
  
  <p>Any ideas how can I ID each process the same way every time?</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>I've simplified the program to this but the idea is the same:</p>
  
  <pre><code>import random, numpy as np,time
  import multiprocessing as mp
  
  def costFunc(i):
      print(mp.current_process().name,mp.Process().name)
      return i*1
  
  class PSO():
      def __init__(self,maxiter,numprocs):
  
          # Begin optimization Loop
          i = 1
          self.Evol = []
  
          while i &lt;= maxiter:
              print('\n' + 'Iteration: %r'%i + '\n')
              pool = mp.Pool(processes = numprocs)
              swarm = pool.map_async(costFunc,(i,))
              pool.close()
              pool.join()
  
              Swarm = swarm.get()
  
              i += 1
  
  if __name__ == "__main__":
      #mp.set_start_method('spawn')
      PSO(10,1)
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>Iteration: 1
  ForkPoolWorker-1 Process-1:1
  Iteration: 2
  ForkPoolWorker-2 Process-2:1
  Iteration: 3
  ForkPoolWorker-3 Process-3:1
  Iteration: 4
  ForkPoolWorker-4 Process-4:1
  Iteration: 5
  ForkPoolWorker-5 Process-5:1
  Iteration: 6
  ForkPoolWorker-6 Process-6:1
  Iteration: 7
  ForkPoolWorker-7 Process-7:1
  Iteration: 8
  ForkPoolWorker-8 Process-8:1
  Iteration: 9
  ForkPoolWorker-9 Process-9:1
  Iteration: 10
  ForkPoolWorker-10 Process-10:1
  </code></pre>