| 44 | ''' |
| 45 | |
| 46 | def __init__(self, maxsize=0): |
| 47 | self.maxsize = maxsize |
| 48 | self._init(maxsize) |
| 49 | |
| 50 | # mutex must be held whenever the queue is mutating. All methods |
| 51 | # that acquire mutex must release it before returning. mutex |
| 52 | # is shared between the three conditions, so acquiring and |
| 53 | # releasing the conditions also acquires and releases mutex. |
| 54 | self.mutex = threading.Lock() |
| 55 | |
| 56 | # Notify not_empty whenever an item is added to the queue; a |
| 57 | # thread waiting to get is notified then. |
| 58 | self.not_empty = threading.Condition(self.mutex) |
| 59 | |
| 60 | # Notify not_full whenever an item is removed from the queue; |
| 61 | # a thread waiting to put is notified then. |
| 62 | self.not_full = threading.Condition(self.mutex) |
| 63 | |
| 64 | # Notify all_tasks_done whenever the number of unfinished tasks |
| 65 | # drops to zero; thread waiting to join() is notified to resume |
| 66 | self.all_tasks_done = threading.Condition(self.mutex) |
| 67 | self.unfinished_tasks = 0 |
| 68 | |
| 69 | # Queue shutdown state |
| 70 | self.is_shutdown = False |
| 71 | |
| 72 | def task_done(self): |
| 73 | '''Indicate that a formerly enqueued task is complete. |