データベースクエリに基づいて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)
どんなアドバイスも素晴らしいでしょう。