我正在使用python读取一个包含一些单词的文件,将所有项目添加到队列中,然后使用doWork()
方法执行操作a
。我试图弄清楚,如何将在a
操作中执行的结果添加回同一队列,以便再次对结果本身执行a
。一旦q
为空,循环就需要停止,并且它最终会停止,因为操作a
可能返回结果,也可能不返回结果
我希望这有点道理P
concurrent = 20
def doWork():
while True:
word = q.get()
lol = getStatus(word)
q.task_done()
def getStatus(word):
#results another word on which this operation has to be performed.
q = Queue(concurrent * 2)
for i in range(concurrent):
t = Thread(target=doWork)
t.daemon = True
t.start()
try:
for words in open('words.txt' ,'r'):
q.put(words.strip())
q.join()
except KeyboardInterrupt:
sys.exit(1)
目前没有回答
相关问题 更多 >
编程相关推荐