title: How to use Python Queues in multiple functions
body: <p>I am having an issue with accessing the queue object within my class in multiple functions, the following code might show you what i am trying to do;</p>
  
  <pre><code>import MySQLdb
  import socket, sys
  from struct import *
  import threading
  import sched, time
  from datetime import datetime
  from copy import deepcopy
  import Queue
  IP = {}
  
  class QP:
  
   def __init__(self):
          self.jobs = Queue.Queue()
  
      # this function runs every 10 seconds
      # and processes any queued data.
   def processQueue(self):
          print(self.jobs.qsize())
          time.sleep(5)
          if self.jobs.empty():
              print("No items in queue")
          else:
              IP_TEMP = {}
              IP_TEMP = self.jobs.get()
              IP_TEMP_QUEUE = {}
              IP_TEMP_QUEUE = IP_TEMP
              try:
                  cnx = #connect to database
                  cursor = cnx.cursor()
                  for k, v in IP_TEMP.iteritems():
  
                      #there is some code here, but its not the issue
  
                      try:
                          cursor.execute(add_packet, data_packet)
                          cnx.commit()
                          print("Task Done")
                      except:
                          print("Query failed, skipping")
                          break
              except:
                  self.queueJobs(IP_TEMP_QUEUE)
  
              IP = {}
              self.jobs.task_done()
              self.processQueue()
  
      # this function is called by other modules to add data
   def queueJobs(self, data):
          self.jobs.put(data)
          print(self.jobs.qsize())
          return True
  </code></pre>
  
  <p>This is how i call the queueJobs method in the other modules:</p>
  
  <pre><code>self.process.queueJobs(IP_TEMP_QUEUE)
  </code></pre>
  
  <p>Now, the main issue is that the <code>processQueue()</code> function always returns that there is no jobs in the queue, even though they have been added below in the <code>queueJobs()</code> function.</p>
  
  <p>Any help would be great!</p>