title: set env var in Python multiprocessing.Process
body: <p>In the <a href="https://docs.python.org/2/library/subprocess.html" rel="noreferrer">subprocess</a> Python 2 module, <a href="https://docs.python.org/2/library/subprocess.html#popen-constructor" rel="noreferrer">Popen</a> can be given an <code>env</code>.</p>
  
  <p>Seems that the equivalent way to do it with <a href="https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Process" rel="noreferrer">Process</a> in <a href="https://docs.python.org/2/library/multiprocessing.html" rel="noreferrer">multiprocessing</a> module is to pass the <code>env</code> dictionnary in <code>args</code> or <code>kwargs</code>, and then use <code>os.environ['FOO'] = value</code> in the <code>target</code>.</p>
  
  <p>Is it the right way?</p>
  
  <p>Is it safe? I mean, no risk that the environment in the parent process or other child processes can be modified?</p>
  
  <p>Here is an example (that works).</p>
  
  <pre><code>import multiprocessing
  import time
  import os
  
  def target(someid):
      os.environ['FOO'] = "foo%i" % someid
      for i in range(10):
          print "Job %i: " % someid, os.environ['FOO']
          time.sleep(1)
  
  if __name__ == '__main__':
  
      processes = []
  
      os.environ['FOO'] = 'foo'
  
      for someid in range(3):
          p = multiprocessing.Process(target=target, args=(someid,))
          p.start()
          processes.append(p)
  
      for i in range(10):
          print "Parent: ", os.environ['FOO']
          time.sleep(1)
  
      for p in processes:
          p.join()
  </code></pre>