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 free sl
(self, item, block=True, timeout=None)
| 135 | return 0 < self.maxsize <= self._qsize() |
| 136 | |
| 137 | def put(self, item, block=True, timeout=None): |
| 138 | '''Put an item into the queue. |
| 139 | |
| 140 | If optional args 'block' is true and 'timeout' is None (the default), |
| 141 | block if necessary until a free slot is available. If 'timeout' is |
| 142 | a non-negative number, it blocks at most 'timeout' seconds and raises |
| 143 | the Full exception if no free slot was available within that time. |
| 144 | Otherwise ('block' is false), put an item on the queue if a free slot |
| 145 | is immediately available, else raise the Full exception ('timeout' |
| 146 | is ignored in that case). |
| 147 | |
| 148 | Raises ShutDown if the queue has been shut down. |
| 149 | ''' |
| 150 | with self.not_full: |
| 151 | if self.is_shutdown: |
| 152 | raise ShutDown |
| 153 | if self.maxsize > 0: |
| 154 | if not block: |
| 155 | if self._qsize() >= self.maxsize: |
| 156 | raise Full |
| 157 | elif timeout is None: |
| 158 | while self._qsize() >= self.maxsize: |
| 159 | self.not_full.wait() |
| 160 | if self.is_shutdown: |
| 161 | raise ShutDown |
| 162 | elif timeout < 0: |
| 163 | raise ValueError("'timeout' must be a non-negative number") |
| 164 | else: |
| 165 | endtime = time() + timeout |
| 166 | while self._qsize() >= self.maxsize: |
| 167 | remaining = endtime - time() |
| 168 | if remaining <= 0.0: |
| 169 | raise Full |
| 170 | self.not_full.wait(remaining) |
| 171 | if self.is_shutdown: |
| 172 | raise ShutDown |
| 173 | self._put(item) |
| 174 | self.unfinished_tasks += 1 |
| 175 | self.not_empty.notify() |
| 176 | |
| 177 | def get(self, block=True, timeout=None): |
| 178 | '''Remove and return an item from the queue. |
no test coverage detected