From 839ca4f77c6624d28cd61f9f8fe297c2ec34af13 Mon Sep 17 00:00:00 2001 From: Thijs Hekman Date: Wed, 21 Jun 2023 10:57:03 +0200 Subject: [PATCH] Added extra flush statements for hdf5 file. This helps for Thijs' machine --- src/lasp/lasp_record.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/lasp/lasp_record.py b/src/lasp/lasp_record.py index 307f2cb..f3086dc 100644 --- a/src/lasp/lasp_record.py +++ b/src/lasp/lasp_record.py @@ -82,8 +82,12 @@ class Recording: self.progressCallback = progressCallback - # Open the file - self.f = h5py.File(self.fn, "w") + try: + # Open the file + self.f = h5py.File(self.fn, "w", 'stdio') + except Exception as e: + logging.error(f'Error creating measurement file {e}') + raise # This flag is used to delete the file on finish(), and can be used # when a recording is canceled. @@ -174,6 +178,7 @@ class Recording: ), compression="gzip", ) + self.f.flush() def inCallback(self, adata): """ @@ -184,6 +189,7 @@ class Recording: """ if self.stop(): + logging.debug('Stop flag set, early return in inCallback') # Stop flag is raised. We do not add any data anymore. return True @@ -201,7 +207,8 @@ class Recording: the recording. Typically used for cleaning up after canceling a recording. """ - self.deleteFile = val + with self.file_mtx: + self.deleteFile = val def finish(self): """ @@ -214,18 +221,21 @@ class Recording: self.stop <<= True with self.file_mtx: - + self.f.flush() # Remove indata handler, which also should remove callback function - # from StreamMgr. - self.indh = None - + # from StreamMgr. This, however does not have to happen + # instantaneously. For which we have to implement extra mutex + # guards in this class + del self.indh + # Remove handle to dataset otherwise the h5 file is not closed # properly. - self.ad = None + del self.ad try: # Close the recording file self.f.close() + del self.f except Exception as e: logging.error(f"Error closing file: {e}") @@ -288,3 +298,4 @@ class Recording: # Add the data to the file, and resize the audio data blocks self.ad.resize(ablockno, axis=0) self.ad[ablockno - 1, :, :] = indata + self.f.flush()