| Total Complexity | 6 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import asyncio |
||
| 2 | import hashlib |
||
| 3 | import logging |
||
| 4 | import pickle |
||
| 5 | |||
| 6 | from itertools import chain, islice |
||
| 7 | |||
| 8 | |||
| 9 | _logger = logging.getLogger(__name__) |
||
| 10 | |||
| 11 | |||
| 12 | class ClientNotFound(Exception): |
||
| 13 | pass |
||
| 14 | |||
| 15 | |||
| 16 | async def event_wait(evt, timeout) -> bool: |
||
| 17 | try: |
||
| 18 | await asyncio.wait_for(evt.wait(), timeout) |
||
| 19 | except asyncio.TimeoutError: |
||
| 20 | pass |
||
| 21 | return evt.is_set() |
||
| 22 | |||
| 23 | |||
| 24 | def get_digest(conf) -> str: |
||
| 25 | return hashlib.md5(pickle.dumps(conf)).hexdigest() |
||
| 26 | |||
| 27 | |||
| 28 | def batch(iterable, size): |
||
| 29 | iterator = iter(iterable) |
||
| 30 | while True: |
||
| 31 | try: |
||
| 32 | batchiter = islice(iterator, size) |
||
| 33 | yield list(chain([next(batchiter)], batchiter)) |
||
| 34 | except StopIteration: |
||
| 35 | break |
||
| 36 |