| 563 | |
| 564 | |
| 565 | class AtomicCount: |
| 566 | def __init__(self, start: int = 0, step: int = 1) -> None: |
| 567 | """Thread-safe atomic counter. Start at start, increment by step.""" |
| 568 | self.count, self.step = start, step |
| 569 | self.lock = threading.Lock() |
| 570 | |
| 571 | def next(self) -> int: |
| 572 | """Get the next value""" |
| 573 | self.lock.acquire() |
| 574 | self.count += self.step |
| 575 | result = self.count |
| 576 | self.lock.release() |
| 577 | return result |
| 578 | |
| 579 | |
| 580 | class SyncRequestResponse(IncomingMessageHandler): |