如何从队列列表中标记项[Python]

时间:2018-05-07 04:09:07

标签: python queue

我在队列中有一个字符串列表

queue = ["First","Second","Third","Fourth","",etc]

代码片段:

import thread
from thread import Threading
import Queue
import time

class MainThread(threading.Thread):
    def __init__(self,queue):
        threading.Thread.__init__(self)
        self.queue = queue

    def run(self):
        Details = self.queue.get()
        Trail = Details
        #..........#
        # Now Mark If Trail Can Be Use Again Or Not
        self.queue.put(Trail) # Now Put Them Back No Matter What
        self.queue.task_done()

queue = Queue.Queue(maxsize=0)
while not #...........#
    for i in range(TotalThreads):
        try:
            t = ThreadingPower(queue)
            t.setDaemon(False)
            t.start()
        except:
            time.sleep(5)

我的问题:如果字符串" First"从队列中无法再次使用,如何在特定时间内标记它,因此线程可以继续抓取其他并忽略它直到特定时间结束

编辑:

目前我的解决方案是

queue = [["First",1],["Second",1],["Third",1],["Fourth",1],etc]


class MainThread(threading.Thread):
    def __init__(self,queue):
        threading.Thread.__init__(self)
        self.queue = queue
    def run(self):
    Details = self.queue.get()
    Trail,State = Details
    if State == 1:
        #................#
        if #.............#:
            State = 0
    self.queue.put((Trail,State)) # Now Put Them Back No Matter What
    self.queue.task_done()

queue = Queue.Queue(maxsize=0)
while not #...........#
    for i in range(TotalThreads):
        try:
            t = ThreadingPower(queue)
            t.setDaemon(False)
            t.start()
        except:
            time.sleep(5)

然而,这仅在我想要永久禁用它们时才有效,我需要一个解决方案,我可以在特定时间禁用它们

0 个答案:

没有答案