diff --git a/oc_ocdm/reader.py b/oc_ocdm/reader.py index 9f95da4..9792ba0 100644 --- a/oc_ocdm/reader.py +++ b/oc_ocdm/reader.py @@ -27,7 +27,6 @@ from oc_ocdm.graph.graph_entity import GraphEntity from oc_ocdm.support.reporter import Reporter from oc_ocdm.support.support import build_graph_from_results - if TYPE_CHECKING: from typing import Any, Dict, List, Optional, Set from oc_ocdm.graph.graph_set import GraphSet diff --git a/oc_ocdm/storer.py b/oc_ocdm/storer.py index 1899c13..d751334 100644 --- a/oc_ocdm/storer.py +++ b/oc_ocdm/storer.py @@ -31,6 +31,7 @@ from oc_ocdm.support.query_utils import get_update_query from oc_ocdm.support.reporter import Reporter from oc_ocdm.support.support import find_paths +from filelock import FileLock if TYPE_CHECKING: from typing import Any, Dict, List, Optional, Set, Tuple @@ -169,13 +170,15 @@ def store_all(self, base_dir: str, base_iri: str, context_path: str = None, proc stored_g = None # Here we try to obtain a reference to the currently stored graph output_filepath = relevant_path.replace(os.path.splitext(relevant_path)[1], ".zip") if self.zip_output else relevant_path - if os.path.exists(output_filepath): - stored_g = Reader(context_map=self.context_map).load(output_filepath) - if stored_g is None: - stored_g = ConjunctiveGraph() - for entity_in_path in entities_in_path: - self.store(entity_in_path, stored_g, relevant_path, context_path, False) - self._store_in_file(stored_g, relevant_path, context_path) + lock = FileLock(f"{output_filepath}.lock") + with lock: + if os.path.exists(output_filepath): + stored_g = Reader(context_map=self.context_map).load(output_filepath) + if stored_g is None: + stored_g = ConjunctiveGraph() + for entity_in_path in entities_in_path: + self.store(entity_in_path, stored_g, relevant_path, context_path, False) + self._store_in_file(stored_g, relevant_path, context_path) return list(relevant_paths.keys()) diff --git a/pyproject.toml b/pyproject.toml index 83acbce..10f9c20 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "oc_ocdm" -version = "8.0.1" +version = "8.0.2" description = "Object mapping library for manipulating RDF graphs that are compliant with the OpenCitations datamodel." authors = [ "Silvio Peroni ",