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
#3
Thank you for the tip. That helped and now it somewhat works. Now the problem is when one file is emitted i.e. goes to the else part, afterward the code gets stuck in OSError loop and goes through the if else loop until the else's break. I tried a few things but nothing worked. It seems the problem is that after emitting the signal, there is no event at self._q.get() so it goes into OSerror until the loop is broken. If during this loop, there is a new file at self._q.get() the file can be emitted once the if/else loop is finished and the process starts again. Tersely: the problem now is the wait time during files. Do you have any idea how I can fix this?


        
while True:
            event = self._q.get()
            max_retry_count = 3500  # 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            
            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:13 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