title: Using MySQL table as a queue with threads in Python
body: <p>I have a DB with a <code>queue</code> table, new entries are inserted continuously in the queue.</p>
  
  <p>I want a Python script to execute the queue as fast as possible, and I think I need some threaded code to do so, running like a daemon.</p>
  
  <p>But I can't figure out how to use the DB as the queue.</p>
  
  <p>I am looking at this example:</p>
  
  <pre><code>import MySQLdb
  from Queue import Queue
  from threading import Thread
  
  def do_stuff(q):
      while True:
          print q.get()
          q.task_done()
  
  q = Queue(maxsize=0)
  num_threads = 10
  
  for i in range(num_threads):
      worker = Thread(target=do_stuff, args=(q,))
      worker.setDaemon(True)
      worker.start()
  
  // TODO:  Use the DB
  db = MySQLdb.connect(...)
  cursor = db.cursor()
  q = cursor.execute("SELECT * FROM queue")
  
  for x in range(100):
      q.put(x)
  q.join()
  </code></pre>