Public Access
Merge performance
Merge branch 'main' of gitea.pkm.physik.tu-darmstadt.de:IPKM/python3-damaris
This commit is contained in:
@@ -110,7 +110,7 @@ class DataPool(collections.abc.MutableMapping):
|
||||
self.__send_event(DataPool.Event(DataPool.Event.destroy))
|
||||
self.__registered_listeners=None
|
||||
|
||||
def write_hdf5(self,hdffile,where="/",name="data_pool", complib=None, complevel=None, incremental=False):
|
||||
def write_hdf5(self,hdffile,where="/",name="data_pool", complib=None, complevel=None, incremental=False, write_interval=0):
|
||||
|
||||
"""
|
||||
Writes the content of a DataPool object to an HDF5 file using the `tables` library.
|
||||
@@ -143,6 +143,17 @@ class DataPool(collections.abc.MutableMapping):
|
||||
Compression level to use when applying compression. Has no effect if `complib`
|
||||
is set to None.
|
||||
|
||||
incremental : bool, optional
|
||||
If True, only write keys that have been modified since the last write (dirty keys).
|
||||
If False, write all keys. Defaults to False.
|
||||
|
||||
write_interval : int, optional
|
||||
Time interval in seconds between periodic writes. If 0, no periodic writes are performed.
|
||||
This parameter affects the writing strategy:
|
||||
- If write_interval is 0: Always use incremental writing for better performance
|
||||
- If write_interval > 0: Only write dirty keys that haven't been written yet
|
||||
Defaults to 0.
|
||||
|
||||
Raises:
|
||||
Exception
|
||||
If `hdffile` is neither a string nor a valid `tables.File` object.
|
||||
@@ -176,6 +187,16 @@ class DataPool(collections.abc.MutableMapping):
|
||||
else:
|
||||
# Full sync: current keys + any other dirty keys (e.g. deletions)
|
||||
dict_keys=list(set(self.__mydict.keys()) | self.__dirty_keys)
|
||||
|
||||
# Apply optimization based on write_interval
|
||||
if write_interval == 0:
|
||||
# No periodic writes: always use incremental writing for better performance
|
||||
dict_keys = list(self.__dirty_keys)
|
||||
elif write_interval > 0 and not incremental:
|
||||
# Periodic writes enabled: only write dirty keys that haven't been written yet
|
||||
# This prevents rewriting objects that were already written in periodic updates
|
||||
dict_keys = list(self.__dirty_keys)
|
||||
|
||||
self.__dictlock.release()
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user