Skip to content

Commit

Permalink
Merge pull request #329 from microbiomedata/328-import-projects-free-…
Browse files Browse the repository at this point in the history
…up-memory

delete large objects and data structs after use
  • Loading branch information
mbthornton-lbl authored Dec 17, 2024
2 parents 1dad830 + ccf191f commit f667b5c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nmdc_automation/run_process/run_import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
import csv
import gc
import importlib.resources
from functools import lru_cache
import logging
Expand Down Expand Up @@ -70,6 +71,8 @@ def import_projects(import_file, import_yaml, site_configuration, iteration):
# validate the database
logger.info("Validating imported data")
db_dict = yaml.safe_load(yaml_dumper.dumps(db))
del db # free up memory
del do_mapping # free up memory
validation_report = linkml.validator.validate(db_dict, nmdc_materialized)
if validation_report.results:
logger.error(f"Validation Failed")
Expand All @@ -93,10 +96,13 @@ def import_projects(import_file, import_yaml, site_configuration, iteration):
logger.info("Posting data to the API")
try:
runtime.post_objects(db_dict)
del db_dict # free up memory
except Exception as e:
logger.error(f"Error posting data to the API: {e}")
raise e

gc.collect()




Expand Down

0 comments on commit f667b5c

Please sign in to comment.