Skip to content

Commit

Permalink
fix statistic
Browse files Browse the repository at this point in the history
  • Loading branch information
mosquito committed May 24, 2023
1 parent 65a0c2d commit 1d66113
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions aiomisc/process_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ def __init__(self, max_workers: int = DEFAULT_MAX_WORKERS, **kwargs: Any):
self._statistic.processes = max_workers

def _statistic_callback(
self, future: Future, execution_time: float,
self,
future: Future,
start_time: float,
loop: asyncio.AbstractEventLoop,
) -> None:
if future.exception():
self._statistic.error += 1
else:
self._statistic.success += 1
self._statistic.done += 1
self._statistic.sum_time += execution_time
self._statistic.sum_time += loop.time() - start_time

def submit(self, *args: Any, **kwargs: Any) -> Future:
"""
Expand All @@ -53,7 +56,7 @@ def submit(self, *args: Any, **kwargs: Any) -> Future:
future = super().submit(*args, **kwargs)
self._statistic.submitted += 1
future.add_done_callback(
lambda f: self._statistic_callback(f, loop.time() - start_time),
lambda f: self._statistic_callback(f, start_time, loop),
)
return future

Expand Down

0 comments on commit 1d66113

Please sign in to comment.