我想根据数据库查询动态地将threading.Thread
类添加到线程中。queue
那可能吗?
例如:
import threading, Queue
class worker(threading.Thread):
def run(self):
while True:
print 'doing stuff'
# get jobs from db
jobs = list(db.Jobs.find())
q = Queue.Queue(5)
for job in jobs:
# instantiate a worker thread here.. don't know how to do this
...
# start new worker thread
new_worker_thread.start()
# then add the worker to the queue
q.put(new_worker_thread)
任何建议都会很棒。