diff --git a/geomagio/Util.py b/geomagio/Util.py index d1cb0a73b1ffc4c164961cddedb8e2b70f973802..e6b74ed980d12473a1af881776e3f8dec40334b2 100644 --- a/geomagio/Util.py +++ b/geomagio/Util.py @@ -4,7 +4,12 @@ from obspy.core import Stats, Trace from obspy import UTCDateTime from io import BytesIO import json -import fcntl +import warnings + +try: + import fcntl +except: + pass class ObjectView(object): @@ -270,6 +275,10 @@ def write_state_file(filename, data, directory=None, encoder=None): fcntl.flock(f, fcntl.LOCK_EX) json.dump(data, f, default=encoder) fcntl.flock(f, fcntl.LOCK_UN) + except NameError as e: + print( + f"The fcntl module is not supported in Windows. Reading/writing state files will not work: {e}" + ) except IOError as e: print(f"Error locking or writing to file: {e}") raise @@ -281,6 +290,9 @@ def write_state_file(filename, data, directory=None, encoder=None): raise +write_state_file("testjunkfile", "dataaaaa", "/home/bgeels/") + + def read_state_file(filename, directory=None, decoder=None): """ Reads data from a state file in a thread-safe manner. @@ -318,6 +330,10 @@ def read_state_file(filename, directory=None, decoder=None): data = json.load(f, object_hook=decoder) fcntl.flock(f, fcntl.LOCK_UN) return data + except NameError as e: + print( + f"The fcntl module is not supported in Windows. Reading/writing state files will not work: {e}" + ) except IOError as e: print(f"Error locking or reading from file: {e}") raise