From ddce731a5d354e833d56a64d06cdbc39711f693e Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Fri, 15 Jan 2021 14:13:00 -0800 Subject: [PATCH] Added retry to use_photos_export, issue #351 --- osxphotos/_version.py | 2 +- osxphotos/photoinfo/_photoinfo_export.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 4c320de9..b2ef6034 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.39.18" +__version__ = "0.39.19" diff --git a/osxphotos/photoinfo/_photoinfo_export.py b/osxphotos/photoinfo/_photoinfo_export.py index 12f46775..fc2603be 100644 --- a/osxphotos/photoinfo/_photoinfo_export.py +++ b/osxphotos/photoinfo/_photoinfo_export.py @@ -51,6 +51,9 @@ from ..photokit import ( ) from ..utils import dd_to_dms_str, findfiles, noop, get_preferred_uti_extension +# retry if use_photos_export fails the first time (which sometimes it does) +MAX_PHOTOSCRIPT_RETRIES = 3 + class ExportError(Exception): """ error during export """ @@ -233,9 +236,16 @@ def _export_photo_uuid_applescript( exported_files = [] filename = None try: - photo = photoscript.Photo(uuid) - filename = photo.filename - exported_files = photo.export(tmpdir.name, original=original, timeout=timeout) + # I've seen intermittent failures with the PhotoScript export so retry if + # export doesn't return anything + retries = 0 + while not exported_files and retries < MAX_PHOTOSCRIPT_RETRIES: + photo = photoscript.Photo(uuid) + filename = photo.filename + exported_files = photo.export( + tmpdir.name, original=original, timeout=timeout + ) + retries += 1 except Exception as e: raise ExportError(e) @@ -268,7 +278,7 @@ def _export_photo_uuid_applescript( exported_paths.append(str(dest_new)) return exported_paths else: - return None + return [] # _check_export_suffix is not a class method, don't import this into PhotoInfo