title: How do I get the exact size of the multiprocessing queue??? docs says it's not reliable. Any way to solve this?
body: <p>I have this code which has two processes
  one is enqueue another is dequeue.</p>
  
  <p>I need to check the the size of the queue for every 60 seconds.
  q.size() does give the result but i want result should be accurate.
  so are there any other ways to do it??</p>
  
  <p>To be exact i need to monitor the input and output of the queue per minute and the size of the queue per minute.</p>
  
  <pre><code>from multiprocessing import Queue, Process
  import os
  import time
  import datetime as dt
  import statsd
  import random
  
  statsd_client = statsd.StatsClient(host="localhost", port=8125, 
  prefix=None, maxudpsize=512, ipv6=False)
  
  
  q = Queue()
  
  
  #put_timer = statsd_client.timer('put')
  def queue_add_proc1():
      print("process 1 Id :", os.getpid())
      print("adding items to queue")
      x = 0
      upload_time = time.time()
  
      enque_count=0
  
      while x &lt; 10000:
          #put_timer.start()
          curr_time = time.time()
          if curr_time - upload_time &gt; 60:
              statsd_client.incr('enque_count_everyMinute', enque_count)
              statsd_client.incr('queue_size_enqueing', q.qsize())
  
              print("metric sent")
              enque_count = 0
              upload_time = curr_time
          q.put(x*2)
          #put_timer.stop(send=True)
          print("added to queue")
          x =x+ 1
          enque_count+=1
          time.sleep(0.014)
          print("done")
  
  
  #pop_timer = statsd_client.timer('get')
  def queue_pop_proc2():
      print("Process 2 ID :",os.getpid())
      print("popping values from queue")
      upload_time = time.time()
      deque_count = 0
      while not q.empty():
          curr_time = time.time()
          if curr_time - upload_time &gt; 60:
              # upload dequed count
              statsd_client.incr('deque_count_everyMinute', deque_count)
              statsd_client.incr('queue_size_dequeing', q.qsize())
              print("metric sent")
              deque_count = 0
              upload_time = curr_time
  
          print(" popped item ", q.get())
          print("dequeued")
          deque_count += 1
          time.sleep(0.03)
  
  
  if __name__ == '__main__':
      msgs_added_each_minute = list()
      msgs_popped_each_minute = list()
  
      print("Main process ID :", os.getpid())
  
      p1 = Process(target=queue_add_proc1)
  
      p2 = Process(target=queue_pop_proc2)
  
      p1.start()
      p2.start()
  
      p2.join()
      p1.join()
  </code></pre>