A thread-safe iterator over tests for multiprocess mode.
| 50 | |
| 51 | # We do not use a generator so multiple threads can call next(). |
| 52 | class MultiprocessIterator: |
| 53 | |
| 54 | """A thread-safe iterator over tests for multiprocess mode.""" |
| 55 | |
| 56 | def __init__(self, tests_iter): |
| 57 | self.lock = threading.Lock() |
| 58 | self.tests_iter = tests_iter |
| 59 | |
| 60 | def __iter__(self): |
| 61 | return self |
| 62 | |
| 63 | def __next__(self): |
| 64 | with self.lock: |
| 65 | if self.tests_iter is None: |
| 66 | raise StopIteration |
| 67 | return next(self.tests_iter) |
| 68 | |
| 69 | def stop(self): |
| 70 | with self.lock: |
| 71 | self.tests_iter = None |
| 72 | |
| 73 | |
| 74 | @dataclasses.dataclass(slots=True, frozen=True) |
no outgoing calls
no test coverage detected
searching dependent graphs…