Skip to content

Commit a4390f5

Browse files
authored
Merge pull request #1846 from olliewalsh/progress
Fix progress bar not reaching 100%
2 parents 7bf82d0 + 62ee0b1 commit a4390f5

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

ramalama/http_client.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,27 @@ def perform_download(self, file, show_progress):
5959
self.start_time = time.time()
6060
accumulated_size = 0
6161
last_update_time = time.time()
62-
while True:
63-
data = self.response.read(1024)
64-
if not data:
65-
return
62+
try:
63+
while True:
64+
data = self.response.read(1024)
65+
if not data:
66+
break
67+
68+
size = file.write(data)
69+
if show_progress:
70+
accumulated_size += size
71+
if time.time() - last_update_time >= 0.1:
72+
self.update_progress(accumulated_size)
73+
accumulated_size = 0
74+
last_update_time = time.time()
6675

67-
size = file.write(data)
6876
if show_progress:
69-
accumulated_size += size
70-
if time.time() - last_update_time >= 0.1:
77+
if accumulated_size > 0:
7178
self.update_progress(accumulated_size)
72-
accumulated_size = 0
73-
last_update_time = time.time()
74-
75-
if accumulated_size > 0:
76-
self.update_progress(accumulated_size)
77-
78-
if show_progress:
79-
perror("\033[K", end="\r")
79+
finally:
80+
if show_progress:
81+
# Output a newline after the progress bar
82+
perror("")
8083

8184
def human_readable_time(self, seconds):
8285
hrs = int(seconds) // 3600

0 commit comments

Comments
 (0)