Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speed up the file checking process while resuming the download #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chiangtw
Copy link

@chiangtw chiangtw commented Mar 7, 2023

In Line 150, the list [(param[1], param[2]) for param in params] should be generated outside of the for loop,
it slows down the resumption of the download process.

with tqdm(total=int(file_size), unit='B', unit_scale=True) as pbar:
params = [
(os.path.join(temporary_directory, self.id), chunk_start_pos,
min(chunk_len, file_size - chunk_start_pos), options, pbar)
for chunk_start_pos in range(0, file_size, chunk_len)]
for file in os.listdir(temporary_directory):
match = re.match(r"(.*)-from-(\d*)-len-(\d*).*", file)
file_id = match.group(1)
file_from = match.group(2)
file_length = match.group(3)
if file_id != self.id:
continue
if (int(file_from), int(file_length)) in [(param[1], param[2]) for param in params]:
continue
logging.warning(f'Deleting the leftover {file} temporary file because the MAX_SLICE_SIZE parameter ('
f'and thus the slice sizes) have been modified since the last run.')
os.remove(os.path.join(temporary_directory, file))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant