Nov-03-2021, 07:40 AM
I solved the problem with the following code if statement:
while True: event = self._q.get() max_retry_count = 350 # for test purposes now but want to set an upper bound on verifying a file is finished. retry_interval_seconds = .01 # every hundreth it will try the file to see if it finished writing retry_count = 0 if event.event_type == "created" and event.src_path.lower().endswith(".hdf5"): while True: try: file = h5py.File(event.src_path, "r") file.close() except OSError: if retry_count < max_retry_count: retry_count += 1 print(f"h5 file <{event.src_path}> is locked, retrying {retry_count}/{max_retry_count}") time.sleep(retry_interval_seconds) else: print(f"h5 file <{event.src_path}> reached max retry count, skipping") break # <--- looks useful here except Exception as err: print(f"Got unexpected Error <{type(err).__name__}> while opening <{event.src_path}> ") traceback.print_exc() else: self.new_file.emit(event.src_path, os.path.basename(event.src_path)) break