title: How do I uses Python's multiprocessing.Value method with .map()?
body: <p>I'm testing some code using multiprocessing to try to understand it, but I'm struggling to get the .Value to work. What am I doing wrong, it says p doesn't exist?</p>
  <p>here's my code:</p>
  <pre><code>from multiprocessing import Pool, Value
  from ctypes import c_int
  if __name__ ==&quot;__main__&quot;:
      p=Value(c_int,1)
  
  
  def addone(a):
      print(a)
  
      with p.get_lock():
          print(p.value)
          p.value += 1
  if __name__ ==&quot;__main__&quot;:
      with Pool() as po:
          po.map(addone,range(19))
      print(p.value)
  </code></pre>
  <p>And I get this error:</p>
  <pre><code>multiprocessing.pool.RemoteTraceback: 
  &quot;&quot;&quot;
  Traceback (most recent call last):
    File &quot;C:\Users\(I removed this)\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py&quot;, line 125, in worker
      result = (True, func(*args, **kwds))
    File &quot;C:\Users\(I removed this)\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py&quot;, line 48, in mapstar
      return list(map(*args))
    File &quot;C:\Users\(I removed this)\Desktop\Python\make\multiTest.py&quot;, line 10, in addone
      with p.get_lock():
  NameError: name 'p' is not defined
  &quot;&quot;&quot;
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File (I removed this), line 15, in &lt;module&gt;
      po.map(addone,range(19))
    File &quot;C:\Users\(I removed this)\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py&quot;, line 364, in map
      return self._map_async(func, iterable, mapstar, chunksize).get()
    File &quot;C:\Users\(I removed this)\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py&quot;, line 771, in get
      raise self._value
  NameError: name 'p' is not defined
  </code></pre>
  <p>What should I do?</p>