fix: 修复浅拷贝导致的 eval 问题
This commit is contained in:
@@ -46,6 +46,7 @@ class PrecachingScreen(Screen):
|
|||||||
for i in nucleons:
|
for i in nucleons:
|
||||||
i: pt.Nucleon
|
i: pt.Nucleon
|
||||||
i.do_eval()
|
i.do_eval()
|
||||||
|
#print("完成 EVAL")
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header(show_clock=True)
|
yield Header(show_clock=True)
|
||||||
@@ -107,17 +108,21 @@ class PrecachingScreen(Screen):
|
|||||||
|
|
||||||
def precache_by_nucleon(self, nucleon: pt.Nucleon):
|
def precache_by_nucleon(self, nucleon: pt.Nucleon):
|
||||||
"""依据 Nucleon 缓存"""
|
"""依据 Nucleon 缓存"""
|
||||||
return self.precache_by_text(nucleon.metadata['formation']['tts_text'])
|
#print(nucleon.metadata['formation']['tts_text'])
|
||||||
|
ret = self.precache_by_text(nucleon.metadata['formation']['tts_text'])
|
||||||
|
return ret
|
||||||
#print(f"TTS 缓存: {nucleon.metadata['formation']['tts_text']}")
|
#print(f"TTS 缓存: {nucleon.metadata['formation']['tts_text']}")
|
||||||
|
|
||||||
def precache_by_list(self, nucleons: list):
|
def precache_by_list(self, nucleons: list):
|
||||||
"""依据 Nucleons 列表缓存"""
|
"""依据 Nucleons 列表缓存"""
|
||||||
for idx, nucleon in enumerate(nucleons):
|
for idx, nucleon in enumerate(nucleons):
|
||||||
|
print(f"PROC: {nucleon}")
|
||||||
worker = get_current_worker()
|
worker = get_current_worker()
|
||||||
if worker and worker.is_cancelled: # 函数在worker中执行且已被取消
|
if worker and worker.is_cancelled: # 函数在worker中执行且已被取消
|
||||||
return False
|
return False
|
||||||
text = nucleon.metadata['formation']['tts_text']
|
text = nucleon.metadata['formation']['tts_text']
|
||||||
self.current_item = text[:30] + "..." if len(text) > 50 else text
|
#self.current_item = text[:30] + "..." if len(text) > 50 else text
|
||||||
|
print(text)
|
||||||
self.processed += 1
|
self.processed += 1
|
||||||
progress = int((self.processed / self.total) * 100) if self.total > 0 else 0
|
progress = int((self.processed / self.total) * 100) if self.total > 0 else 0
|
||||||
self.update_status(
|
self.update_status(
|
||||||
@@ -134,11 +139,17 @@ class PrecachingScreen(Screen):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def precache_by_nucleons(self):
|
def precache_by_nucleons(self):
|
||||||
return self.precache_by_list(self.nucleons)
|
#print("开始缓存")
|
||||||
|
ret = self.precache_by_list(self.nucleons)
|
||||||
|
#print(f"返回 {ret}")
|
||||||
|
return ret
|
||||||
|
|
||||||
def precache_by_filepath(self, path: pathlib.Path):
|
def precache_by_filepath(self, path: pathlib.Path):
|
||||||
"""预缓存单个文件的所有内容"""
|
"""预缓存单个文件的所有内容"""
|
||||||
return self.precache_by_list(pt.load_nucleon(path)[0])
|
lst = list()
|
||||||
|
for i in pt.load_nucleon(path):
|
||||||
|
lst.append(i[0])
|
||||||
|
return self.precache_by_list(lst)
|
||||||
|
|
||||||
|
|
||||||
def precache_all_files(self):
|
def precache_all_files(self):
|
||||||
@@ -177,9 +188,9 @@ class PrecachingScreen(Screen):
|
|||||||
if event.button.id == "start_precache" and not self.is_precaching:
|
if event.button.id == "start_precache" and not self.is_precaching:
|
||||||
# 开始预缓存
|
# 开始预缓存
|
||||||
if self.nucleons:
|
if self.nucleons:
|
||||||
self.precache_worker = self.run_worker(self.precache_by_nucleons, thread=True)
|
self.precache_worker = self.run_worker(self.precache_by_nucleons, thread=True, exclusive=True, exit_on_error=True)
|
||||||
else:
|
else:
|
||||||
self.precache_worker = self.run_worker(self.precache_all_files, thread=True)
|
self.precache_worker = self.run_worker(self.precache_all_files, thread=True, exclusive=True, exit_on_error=True)
|
||||||
|
|
||||||
elif event.button.id == "cancel_precache" and self.is_precaching:
|
elif event.button.id == "cancel_precache" and self.is_precaching:
|
||||||
# 取消预缓存
|
# 取消预缓存
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import heurams.services.hasher as hasher
|
|||||||
import pathlib
|
import pathlib
|
||||||
import toml
|
import toml
|
||||||
import json
|
import json
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
||||||
with open(path, "r") as f:
|
with open(path, "r") as f:
|
||||||
@@ -28,7 +29,7 @@ def load_nucleon(path: pathlib.Path, fmt = "toml"):
|
|||||||
for item, attr in nested_data.items():
|
for item, attr in nested_data.items():
|
||||||
if item == "__metadata__":
|
if item == "__metadata__":
|
||||||
continue
|
continue
|
||||||
lst.append((Nucleon(hasher.hash(item), attr, nested_data['__metadata__']), nested_data["__metadata__"]["orbital"]))
|
lst.append((Nucleon(hasher.hash(item), attr, deepcopy(nested_data['__metadata__'])), deepcopy(nested_data["__metadata__"]["orbital"])))
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
def load_electron(path: pathlib.Path, fmt = "json") -> dict:
|
def load_electron(path: pathlib.Path, fmt = "json") -> dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user