revise space logics

This commit is contained in:
layerdiffusion
2024-08-19 08:06:24 -07:00
parent 96f264ec6a
commit 054a3416f1

View File

@@ -131,6 +131,11 @@ class ForgeSpace:
def gradio_worker(self):
import spaces
spaces.unload_module()
original_cwd = os.getcwd()
os.chdir(self.hf_path)
if 'models' in sys.modules:
del sys.modules['models']
memory_management.unload_all_models()
sys.path.insert(0, self.hf_path)
@@ -155,17 +160,21 @@ class ForgeSpace:
server_port=port
)
if module_name in sys.modules:
del sys.modules[module_name]
if 'models' in sys.modules:
del sys.modules['models']
sys.path.remove(self.hf_path)
sys.path.remove(self.root_path)
os.chdir(original_cwd)
while self.is_running:
time.sleep(0.1)
demo.close()
self.gradio_metas = None
if module_name in sys.modules:
del sys.modules[module_name]
sys.path.remove(self.hf_path)
sys.path.remove(self.root_path)
return