Passed
Pull Request — master (#367)
by
unknown
02:46
created

utils   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A get_digest() 0 2 1
A batch() 0 8 3
A event_wait() 0 6 2
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