title: Multiprocessing Pause-Restart functionality using `event`
body: <p>I am using a code posted below to enable <strong>pause-restart</strong> functionality for <code>multiprocessing</code> Pool.</p>
  
  <p>I would appreciate if you explain me why <code>event</code> variable has to be sent as an argument to <code>setup()</code> function. Why then a global variable <code>unpaused</code> is declared inside of the scope of <code>setup()</code> function  and then it is set to be the same as <code>event</code> variable:</p>
  
  <pre><code>def setup(event):
      global unpaused
      unpaused = event
  </code></pre>
  
  <p>I also would like to know a logistic behind of the following declaration:</p>
  
  <pre><code>pool=mp.Pool(2, setup, (event,))
  </code></pre>
  
  <p>The first argument submitted is the number of the CPU cores to be used by Pool. 
  The second argument submitted is a function <code>setup()</code> which is mentioned above. </p>
  
  <p>Why wouldn't it all be accomplished like:</p>
  
  <pre><code>global event
  event=mp.Event()
  pool = mp.Pool(processes=2)
  </code></pre>
  
  <p>And every time we need to pause or to restart a job we would just use:</p>
  
  <p>To pause:</p>
  
  <pre><code>event.clear()
  </code></pre>
  
  <p>To restart:</p>
  
  <pre><code>event.set()
  </code></pre>
  
  <p>Why would we need a global variable <code>unpaused</code>? I don't get it! Please advise.</p>
  
  <hr>
  
  <pre><code>import time
  import multiprocessing as mp
  
  def myFunct(arg):
      proc=mp.current_process()
      print 'starting:', proc.name, proc.pid,'...\n'
      for i in range(110):
          for n in range(500000):
              pass
      print '\t ...', proc.name, proc.pid, 'completed\n'
  
  def setup(event):
      global unpaused
      unpaused = event
  
  def pauseJob():
      event.clear()
  
  def continueJob():
      event.set()
  
  
  event=mp.Event()
  
  pool=mp.Pool(2, setup, (event,))
  pool.map_async(myFunct, [1,2,3])
  
  event.set()
  
  pool.close()
  pool.join()
  </code></pre>