From 162995fca3480d097ef2b839bdbc6a651a54dcc0 Mon Sep 17 00:00:00 2001 From: Hiroshi Miura Date: Wed, 8 Dec 2021 08:32:16 +0900 Subject: [PATCH] Invoke gc.collect() when close() called Signed-off-by: Hiroshi Miura --- py7zr/py7zr.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/py7zr/py7zr.py b/py7zr/py7zr.py index 356d0b03..e4d1a237 100644 --- a/py7zr/py7zr.py +++ b/py7zr/py7zr.py @@ -28,6 +28,7 @@ import datetime import errno import functools +import gc import io import os import pathlib @@ -783,10 +784,12 @@ def _is_solid(self): def _var_release(self): self._dict = None - self.files = None - self.header = None - self.worker = None - self.sig_header = None + self.worker.close() + del self.worker + del self.files + del self.header + del self.sig_header + gc.collect() @staticmethod def _make_file_info(target: pathlib.Path, arcname: Optional[str] = None, dereference=False) -> Dict[str, Any]: @@ -1448,3 +1451,8 @@ def archive(self, fp: BinaryIO, files, folder, deref=False): def register_filelike(self, id: int, fileish: Union[MemIO, pathlib.Path, None]) -> None: """register file-ish to worker.""" self.target_filepath[id] = fileish + + def close(self): + del self.header + del self.files + del self.concurrent \ No newline at end of file