I have a DB with a queue
table, new entries are inserted continuously in the queue.
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.
But I can't figure out how to use the DB as the queue.
I am looking at this example:
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()