| 92 | return frame |
| 93 | |
| 94 | def reset_queue(self, frames: Iterable[Frame]) -> None: |
| 95 | # Helper to put frames back into the queue after they were fetched. |
| 96 | # This happens only when the queue is empty. However, by the time |
| 97 | # we acquire self.mutex, put() may have added items in the queue. |
| 98 | # Therefore, we must handle the case where the queue is not empty. |
| 99 | frame: Frame | None |
| 100 | with self.mutex: |
| 101 | queued = [] |
| 102 | try: |
| 103 | while True: |
| 104 | queued.append(self.frames.get(block=False)) |
| 105 | except queue.Empty: |
| 106 | pass |
| 107 | for frame in frames: |
| 108 | self.frames.put(frame) |
| 109 | # This loop runs only when a race condition occurs. |
| 110 | for frame in queued: # pragma: no cover |
| 111 | self.frames.put(frame) |
| 112 | |
| 113 | # This overload structure is required to avoid the error: |
| 114 | # "parameter without a default follows parameter with a default" |