Skip to content

Commit

Permalink
Merge pull request #279 from pieces-app/fix-installation
Browse files Browse the repository at this point in the history
fix installation taking to so long
  • Loading branch information
bishoy-at-pieces authored Mar 3, 2025
2 parents 7fcef34 + 3137b07 commit b097c76
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions _pieces_lib/pieces_os_client/wrapper/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import subprocess
from enum import Enum
from tempfile import gettempdir
import asyncio
import re
import threading
import time
Expand Down Expand Up @@ -116,6 +115,9 @@ def download_windows(self):
self.install_using_web(pkg_url, tmp_pkg_path)

def install_using_web(self, pkg_url: str, tmp_pkg_path: str) -> bool:
BUFFER_SIZE = 65536
STALL_TIMEOUT = 5

try:
self.state = DownloadState.DOWNLOADING
request = urllib.request.Request(pkg_url, headers={'Accept': '*/*'})
Expand All @@ -124,8 +126,9 @@ def install_using_web(self, pkg_url: str, tmp_pkg_path: str) -> bool:
downloaded_size = 0

with open(tmp_pkg_path, 'wb') as out_file:
last_data_time = time.time()
while True:
data = response.read(1024)
data = response.read(BUFFER_SIZE)
if not data:
break
if self.stop:
Expand All @@ -135,7 +138,14 @@ def install_using_web(self, pkg_url: str, tmp_pkg_path: str) -> bool:

out_file.write(data)
downloaded_size += len(data)
time.sleep(0.2)
last_data_time = time.time()

if downloaded_size % (512 * 1024) == 0 or downloaded_size == file_size:
self.update_progress(downloaded_size, file_size)
self.print(f'Downloaded {downloaded_size} of {file_size}')
if time.time() - last_data_time > STALL_TIMEOUT:
raise TimeoutError("Download stalled (no data received).")

self.update_progress(downloaded_size, file_size)
self.print(f'Downloaded {downloaded_size} of {file_size}')

Expand Down

0 comments on commit b097c76

Please sign in to comment.