Put an item into the queue. If optional args 'block' is true and 'timeout' is None (the default), block if necessary until a free slot is available. If 'timeout' is a non-negative number, it blocks at most 'timeout' seconds and raises the Full exception if no fr
(self, item, block=True, timeout=None)
| 120 | return 0 < self.maxsize <= self._qsize() |
| 121 | |
| 122 | def put(self, item, block=True, timeout=None): |
| 123 | '''Put an item into the queue. |
| 124 | |
| 125 | If optional args 'block' is true and 'timeout' is None (the default), |
| 126 | block if necessary until a free slot is available. If 'timeout' is |
| 127 | a non-negative number, it blocks at most 'timeout' seconds and raises |
| 128 | the Full exception if no free slot was available within that time. |
| 129 | Otherwise ('block' is false), put an item on the queue if a free slot |
| 130 | is immediately available, else raise the Full exception ('timeout' |
| 131 | is ignored in that case). |
| 132 | ''' |
| 133 | with self.not_full: |
| 134 | if self.maxsize > 0: |
| 135 | if not block: |
| 136 | if self._qsize() >= self.maxsize: |
| 137 | raise Full |
| 138 | elif timeout is None: |
| 139 | while self._qsize() >= self.maxsize: |
| 140 | self.not_full.wait() |
| 141 | elif timeout < 0: |
| 142 | raise ValueError("'timeout' must be a non-negative number") |
| 143 | else: |
| 144 | endtime = time() + timeout |
| 145 | while self._qsize() >= self.maxsize: |
| 146 | remaining = endtime - time() |
| 147 | if remaining <= 0.0: |
| 148 | raise Full |
| 149 | self.not_full.wait(remaining) |
| 150 | self._put(item) |
| 151 | self.unfinished_tasks += 1 |
| 152 | self.not_empty.notify() |
| 153 | |
| 154 | def get(self, block=True, timeout=None): |
| 155 | '''Remove and return an item from the queue. |