core: add error count to stats helper

This commit is contained in:
Dima Gerasimov 2020-07-30 22:03:26 +01:00 committed by karlicoss
parent 92307d5f3d
commit a9ae6dbb7f

View file

@ -365,7 +365,16 @@ C = TypeVar('C')
def stat(func: Callable[[], Iterable[C]]) -> Dict[str, Any]: def stat(func: Callable[[], Iterable[C]]) -> Dict[str, Any]:
from more_itertools import ilen, take, first from more_itertools import ilen, take, first
it = iter(func()) # todo not sure if there is something in more_itertools to compute this?
errors = 0
def funcit():
nonlocal errors
for x in func():
if isinstance(x, Exception):
errors += 1
yield x
it = iter(funcit())
res: Any res: Any
if QUICK_STATS: if QUICK_STATS:
initial = take(100, it) initial = take(100, it)
@ -377,6 +386,10 @@ def stat(func: Callable[[], Iterable[C]]) -> Dict[str, Any]:
res = ilen(it) res = ilen(it)
if errors > 0:
# todo not sure, but for now ok
res = f'{res} ({errors} errors)'
return { return {
func.__name__: res, func.__name__: res,
} }