How check if a task is already in python Queue?

后端 未结 12 2483
青春惊慌失措
青春惊慌失措 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:35

    Sadly, I have no enouch rating for comment the best Lukáš Lalinský’s answer.

    To add support for SetQueue.task_done() and SetQueue.join() for second variant of Lukáš Lalinský’s SetQueue add else brahch to the if:

    def _put(self, item):
        if item not in self.all_items:
            Queue._put(self, item);
            self.all_items.add(item);
        else:
            self.unfinished_tasks -= 1;
    

    Tested and works with Python 3.4.

提交回复
热议问题