mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
moved cleanup routine into object_serializer_disk.py
This commit is contained in:
parent
21ba55d0a6
commit
53808149fb
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user