From 3f6525cddc4aeed675a1b35d23fc236b4fb358dc Mon Sep 17 00:00:00 2001 From: Zhaoyu Yang Date: Thu, 6 Aug 2026 15:32:27 -0400 Subject: [PATCH] Fix the infinite looping bug in file uploading and download --- DM-55747.bugfix.rst | 1 + python/lsst/ctrl/bps/panda/utils.py | 22 +++++++++------------- 2 files changed, 10 insertions(+), 13 deletions(-) create mode 100644 DM-55747.bugfix.rst diff --git a/DM-55747.bugfix.rst b/DM-55747.bugfix.rst new file mode 100644 index 0000000..ffc5c29 --- /dev/null +++ b/DM-55747.bugfix.rst @@ -0,0 +1 @@ +Fixed maxattemps not working in upload and download files from panda cache diff --git a/python/lsst/ctrl/bps/panda/utils.py b/python/lsst/ctrl/bps/panda/utils.py index f598943..539d6fc 100644 --- a/python/lsst/ctrl/bps/panda/utils.py +++ b/python/lsst/ctrl/bps/panda/utils.py @@ -1015,13 +1015,11 @@ def create_archive_file(submit_path, archive_filename, files): def copy_files_to_pandacache(filename): from pandaclient import Client - attempt = 0 max_attempts = 3 - done = False - while attempt < max_attempts and not done: + for _ in range(max_attempts): status, out = Client.putFile(filename, True) if status == 0: - done = True + break print(f"copy_files_to_pandacache: status: {status}, out: {out}") if out.startswith("NewFileName:"): # found the same input sandbox to reuse @@ -1063,19 +1061,17 @@ def download_extract_archive(filename, prefix=None): # Otherwise, the PanDA client the environment setting will not be parsed. from pandaclient import Client - attempt = 0 max_attempts = 3 - while attempt < max_attempts: + for attempt in range(max_attempts): status, output = Client.getFile(archive_basename, output_path=full_output_filename) if status == 0: break - if attempt <= 1: - secs = random.randint(1, 10) - elif attempt <= 2: - secs = random.randint(1, 60) - else: - secs = random.randint(1, 120) - time.sleep(secs) + if attempt < max_attempts - 1: + if attempt < 2: + secs = random.randint(1, 10) + else: + secs = random.randint(1, 60) + time.sleep(secs) print(f"Download archive file from pandacache status: {status}, output: {output}") if status != 0: raise RuntimeError("Failed to download archive file from pandacache")