diff --git a/deeplake/enterprise/dataloader.py b/deeplake/enterprise/dataloader.py index 2ecd98e115..d97ae577ef 100644 --- a/deeplake/enterprise/dataloader.py +++ b/deeplake/enterprise/dataloader.py @@ -424,8 +424,9 @@ def sample_by( def close(self): """Shuts down the workers and releases the resources.""" + if self._internal_iterator is not None: + self._internal_iterator = None if self._dataloader is not None: - self._dataloader.close() self._dataloader = None def pytorch( @@ -781,8 +782,10 @@ def __iter__(self): dataset_read(self._orig_dataset) + if self._internal_iterator is not None: self._internal_iterator = iter(self._internal_iterator) + return self def __next__(self): @@ -792,6 +795,9 @@ def __next__(self): self._internal_iterator = iter(self._dataloader) return next(self._internal_iterator) + def __del__(self): + self.close() + def dataloader(dataset, ignore_errors: bool = False) -> DeepLakeDataLoader: """Returns a :class:`~deeplake.enterprise.dataloader.DeepLakeDataLoader` object which can be transformed to either pytorch dataloader or numpy.