Python Forum
Using .hdf5 files only once they are finished writing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using .hdf5 files only once they are finished writing
#4
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
Reply


Messages In This Thread
RE: Using .hdf5 files only once they are finished writing - by pyhill00 - Nov-03-2021, 07:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Writing into 2 text files from the same function paul18fr 4 1,774 Jul-28-2022, 04:34 AM
Last Post: ndc85430
  Process finished with exit code 137 (interrupted by signal 9: SIGKILL) erdemath 2 9,782 Apr-18-2022, 08:40 PM
Last Post: erdemath
  How to check if a file has finished being written leocsmith 2 8,090 Apr-14-2021, 04:21 PM
Last Post: perfringo
  process finished with exit code -1073741819 (0xC0000005) GMCobraz 8 5,621 Sep-01-2020, 08:19 AM
Last Post: GMCobraz
  How to stop Xmodem after bin file transfer was finished shaya2103 0 2,589 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  Reading and writing files JakeHoward4 1 1,873 Aug-07-2019, 06:22 PM
Last Post: Yoriz
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 8,575 Apr-05-2019, 12:46 PM
Last Post: mrazko
  Fabric - Run method is not being finished mglowinski93 3 3,780 Dec-29-2018, 10:45 AM
Last Post: mglowinski93
  Progress Finished Question malonn 32 17,967 May-23-2018, 02:43 AM
Last Post: malonn
  Help writing to files HummingMaster 3 3,630 Mar-12-2017, 05:24 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020