Skip to content

Instantly share code, notes, and snippets.

View erfannoury's full-sized avatar

Erfan Noury erfannoury

View GitHub Profile
@erfannoury
erfannoury / SetQueue.py
Last active August 29, 2015 14:13
a thread-safe queue + set implementation
from Queue import Queue
from threading import RLock
class SetQueue(Queue):
"""
Queue class is thread-safe, so it can be used in scenarios where multiple threads will try accessing the queue.
But default implementation has a downside, it is not iterable and you can't check if it contains an item or not,
so you can't see if you are adding a duplicate item or not.
To overcome this problem, a SetQueue implementation is propsed.
This implementation is grabbed from here: http://stackoverflow.com/questions/1581895/how-check-if-a-task-is-already-in-python-queue