I am trying to run some multithreaded code in python as
from Queue import Queue
q = Queue()
doclist=["adsas","asdasd","oipoipo"]
for i,doc in enumerate(doclist):
q.put(doc)
q.join()
threadRun.run(50, qWorker.worker(q))
first, i create a queue and add some stuff to it. Then, i call a method which creates and runs the threads. Here is the threadRun.run
method
import threading
def run(numThreads,targetMethod):
print "Running threads"
for i in range(numThreads):
t = threading.Thread(target=targetMethod)
t.daemon=True
t.start()
and here is the qWorker.worker
method
def worker(qItem):
print "Q Worker"
while True:
doc = qItem.get()
try:
print doc
qItem.task_done()
except:
print "Error"
When i execute the above code, nothing happens. Is my approach correct? what am i missing?