moved cleanup routine into object_serializer_disk.py

This commit is contained in:
Lincoln Stein 2024-04-22 21:33:17 -04:00 committed by psychedelicious
parent 21ba55d0a6
commit 53808149fb
2 changed files with 12 additions and 11 deletions

View File

@ -1,8 +1,6 @@
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
import shutil
from logging import Logger
from pathlib import Path
import torch
@ -54,14 +52,6 @@ def check_internet() -> bool:
return False
def cleanup_tmpdirs(parent_folder: Path) -> None:
# Remove dangling tempdirs that might have been left over
# from an earlier unplanned shutdown.
for d in parent_folder.glob("tmp*"):
if d.is_dir():
shutil.rmtree(d)
logger = InvokeAILogger.get_logger()
@ -88,7 +78,6 @@ class ApiDependencies:
configuration = config
logger = logger
cleanup_tmpdirs(tensor_folder)
board_image_records = SqliteBoardImageRecordStorage(db=db)
board_images = BoardImagesService()
board_records = SqliteBoardRecordStorage(db=db)

View File

@ -1,3 +1,4 @@
import shutil
import tempfile
import typing
from dataclasses import dataclass
@ -81,5 +82,16 @@ class ObjectSerializerDisk(ObjectSerializerBase[T]):
# In case the service is not properly stopped, clean up the temporary directory when the class instance is GC'd.
self._tempdir_cleanup()
@classmethod
def _cleanup_dangling_temporary_dirs(cls, directory: Path):
# Remove dangling tempdirs that might have been left over
# from an earlier unplanned shutdown.
for d in directory.glob("tmp*"):
if d.is_dir():
shutil.rmtree(d)
def start(self, invoker: "Invoker") -> None:
self._cleanup_dangling_temporary_dirs(self._base_output_dir)
def stop(self, invoker: "Invoker") -> None:
self._tempdir_cleanup()