diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index ab242cc61052cf904d5ca115694d5eb89e1b6ea8..8036b7ac488f7a621267ded32729cf722ff56101 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -434,15 +434,20 @@ def get_dir_creation_date(directory, run, tsdir=False): :param tsdir: to get modification time of [directory]/[run]04. :return: (datetime) modification time """ - if tsdir: - creation_time = stat("{}/r{:04d}".format(directory, run)).st_mtime - else: - rfiles = glob("{}/r{:04d}/*.h5".format(directory, run)) - rfiles.sort(key=path.getmtime) - creation_time = stat(rfiles[0]).st_mtime + ntries = 100 + while ntries > 0: + try: + if tsdir: + creation_time = stat("{}/r{:04d}".format(directory, run)).st_mtime + else: + rfiles = glob("{}/r{:04d}/*.h5".format(directory, run)) + rfiles.sort(key=path.getmtime) + creation_time = stat(rfiles[0]).st_mtime - creation_time = datetime.datetime.fromtimestamp(creation_time) - return creation_time + creation_time = datetime.datetime.fromtimestamp(creation_time) + return creation_time + except: # catch stale file handle errors etc and try again + ntries -= 1 def get_random_db_interface(cal_db_interface): @@ -500,7 +505,6 @@ def get_from_db(device, constant, condition, empty_constant, metadata.calibration_constant_version = Versions.Timespan( device=device, start=creation_time) - while ntries > 0: this_interface = get_random_db_interface(cal_db_interface)