Skip to content
Snippets Groups Projects

Hotfix for Windows OS support

1 file
+ 17
1
Compare changes
  • Side-by-side
  • Inline
+ 17
1
@@ -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
Loading