use a 'with' context

This commit is contained in:
Alex "mcmonkey" Goodwin 2024-09-19 17:04:54 +09:00
parent cd71722b11
commit d66e844c1a
2 changed files with 17 additions and 11 deletions

View File

@ -66,6 +66,14 @@ class CacheHelper:
def clear(self):
self.cache.clear()
def __enter__(self):
self.active = True
return self
def __exit__(self, exc_type, exc_value, traceback):
self.active = False
self.clear()
cache_helper = CacheHelper()
extension_mimetypes_cache = {

View File

@ -552,17 +552,15 @@ class PromptServer():
@routes.get("/object_info")
async def get_object_info(request):
folder_paths.cache_helper.clear()
folder_paths.cache_helper.active = True
out = {}
for x in nodes.NODE_CLASS_MAPPINGS:
try:
out[x] = node_info(x)
except Exception as e:
logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.")
logging.error(traceback.format_exc())
folder_paths.cache_helper.active = False
return web.json_response(out)
with folder_paths.cache_helper:
out = {}
for x in nodes.NODE_CLASS_MAPPINGS:
try:
out[x] = node_info(x)
except Exception as e:
logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.")
logging.error(traceback.format_exc())
return web.json_response(out)
@routes.get("/object_info/{node_class}")
async def get_object_info_node(request):