mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-13 02:47:01 +08:00
use a 'with' context
This commit is contained in:
parent
cd71722b11
commit
d66e844c1a
@ -66,6 +66,14 @@ class CacheHelper:
|
|||||||
def clear(self):
|
def clear(self):
|
||||||
self.cache.clear()
|
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()
|
cache_helper = CacheHelper()
|
||||||
|
|
||||||
extension_mimetypes_cache = {
|
extension_mimetypes_cache = {
|
||||||
|
|||||||
@ -552,8 +552,7 @@ class PromptServer():
|
|||||||
|
|
||||||
@routes.get("/object_info")
|
@routes.get("/object_info")
|
||||||
async def get_object_info(request):
|
async def get_object_info(request):
|
||||||
folder_paths.cache_helper.clear()
|
with folder_paths.cache_helper:
|
||||||
folder_paths.cache_helper.active = True
|
|
||||||
out = {}
|
out = {}
|
||||||
for x in nodes.NODE_CLASS_MAPPINGS:
|
for x in nodes.NODE_CLASS_MAPPINGS:
|
||||||
try:
|
try:
|
||||||
@ -561,7 +560,6 @@ class PromptServer():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.")
|
logging.error(f"[ERROR] An error occurred while retrieving information for the '{x}' node.")
|
||||||
logging.error(traceback.format_exc())
|
logging.error(traceback.format_exc())
|
||||||
folder_paths.cache_helper.active = False
|
|
||||||
return web.json_response(out)
|
return web.json_response(out)
|
||||||
|
|
||||||
@routes.get("/object_info/{node_class}")
|
@routes.get("/object_info/{node_class}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user