How check if a task is already in python Queue?

后端 未结 12 2468
青春惊慌失措
青春惊慌失措 2020-12-05 15:04

I\'m writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished proc

12条回答
  •  再見小時候
    2020-12-05 15:41

    I'm agree with @Ben James.Try to use both deque and set.

    here are code:

    class SetUniqueQueue(Queue):
    
        def _init(self, maxsize):
            self.queue = deque()
            self.setqueue = set()
    
        def _put(self, item):
            if item not in self.setqueue:
                self.setqueue.add(item)
                self.queue.append(item)
    
        def _get(self):
            return self.queue.popleft()
    

提交回复
热议问题