title: I'm trying to calculate a probability of a function returning True by while(True) looping it in Python but I can't get it to work
body: <p>I'm trying to calculate the probability of a predefined function that símulates an arbitrary event. Is there maybe a library that does this or a better way?</p>
  <pre><code>from multiprocessing import cpu_count
  import multiprocessing
  
  def play_event():
      &quot;predefined function which either returns True or False&quot;
  
  def process(total_events, favorable_results, lock):
      while(True):
          event = play_event()
          with lock:
              total_events += 1
              if(event == True):
                  favorable_results += 1
          
  
  if __name__ == &quot;__main__&quot;:
      seed(1)
  
      manager = multiprocessing.Manager()
      lock = manager.Lock()
      number_processes = cpu_count()
  
      total_events = manager.Value(int, 0)
      favorable_results = manager.Value(int, 0)
  
      jobs = []
  
      for i in range(number_processes):
          p = multiprocessing.Process(target=process, args=(total_events, favorable_results, lock))
          jobs.append(p)
          p.start()
  
      while(True):
          if(total_events.value &gt; 0):
              print(Decimal(favorable_results.value)/total_events.value)
  </code></pre>
  <p>Right now I'm getting the error: TypeError: unsupported operand type(s) for +=: 'ValueProxy' and 'int', in the process function when i add 1 to the total_events. Unfortunately, I don't think this is the only error. Before I didn't get this error and total_events.value was constantly 1.</p>