diff --git a/eoreader/reader.py b/eoreader/reader.py index 95712077..381a8141 100644 --- a/eoreader/reader.py +++ b/eoreader/reader.py @@ -21,6 +21,7 @@ import importlib import logging import re +from contextlib import contextmanager from enum import unique from typing import Union from zipfile import BadZipFile @@ -448,6 +449,7 @@ def _compile_(regex_str: str): return comp + @contextmanager def open( self, product_path: AnyPathStrType, @@ -550,8 +552,10 @@ def open( "There is no existing products in EOReader corresponding to %s", product_path, ) - - return prod + try: + yield prod + finally: + del prod def _open_stac_item( self, item: Item, output_path: AnyPathStrType, remove_tmp: bool, **kwargs