Skip to content

Commit

Permalink
Updating progress (or your callback_function) only when the progress …
Browse files Browse the repository at this point in the history
…has increased
  • Loading branch information
TechShreyash committed Jun 28, 2024
1 parent 0014fd8 commit c9016d7
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions techzdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,30 @@ async def _show_progress(self, description: str) -> None:
Args:
description (str): Description for the progress display.
"""
previous_size = 0

if self.progress_callback:
while self.size_done < self.total_size:
if self.is_callback_async:
await self.progress_callback(
description,
self.size_done,
self.total_size,
*self.progress_args,
)
else:
self.progress_callback(
description,
self.size_done,
self.total_size,
*self.progress_args,
)
if self.size_done != previous_size:
if self.is_callback_async:
await self.progress_callback(
description,
self.size_done,
self.total_size,
*self.progress_args,
)
else:
self.progress_callback(
description,
self.size_done,
self.total_size,
*self.progress_args,
)

previous_size = self.size_done

await asyncio.sleep(self.progress_interval)

if self.is_callback_async:
await self.progress_callback(
description, self.total_size, self.total_size, *self.progress_args
Expand All @@ -325,10 +332,11 @@ async def _show_progress(self, description: str) -> None:
desc=description,
bar_format="{desc}: {percentage:3.0f}% |{bar}| {n_fmt}B/{total_fmt}B [{elapsed}<{remaining}, {rate_fmt}{postfix}]",
) as pbar:
previous_size = 0
while self.size_done < self.total_size:
pbar.update(self.size_done - previous_size)
previous_size = self.size_done
if self.size_done != previous_size:
pbar.update(self.size_done - previous_size)
previous_size = self.size_done

await asyncio.sleep(self.progress_interval)
pbar.update(self.total_size - previous_size)

Expand Down

0 comments on commit c9016d7

Please sign in to comment.