Skip to content

Commit

Permalink
🐛Implemented __del__ for AsyncDataLoaderIter
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed Oct 18, 2024
1 parent 627f98c commit 87ac7c6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/learn/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class AsyncDataLoaderIter(_SingleProcessDataLoaderIter):
_drained: bool
_queue_cursor: int
_dataset: IAsyncDataset
_finalized: bool

def __init__(self, loader: "DataLoader"):
super().__init__(loader)
Expand All @@ -271,17 +272,24 @@ def __init__(self, loader: "DataLoader"):
raise RuntimeError(
"async prefetch is only available for `IAsyncDataset`"
) # pragma: no cover
self._finalized = True
self._initialized = False

def __del__(self) -> None:
if not self._finalized:
self._dataset.async_finalize()

def _initialize(self) -> None:
self._queue = None
self._drained = False
self._queue_cursor = 0
self._dataset.async_reset()
self._finalized = False
self._initialized = True

def _finalize(self) -> None:
self._dataset.async_finalize()
self._finalized = True
raise StopIteration

def _sumbit_next(self) -> None:
Expand Down

0 comments on commit 87ac7c6

Please sign in to comment.