保存配置到 config.json
(self)
| 52 | self._config_data = json.load(f) |
| 53 | |
| 54 | def _save_config(self): |
| 55 | """保存配置到 config.json""" |
| 56 | with self._lock: # 加锁确保线程安全 |
| 57 | # 移除循环引用并写入 |
| 58 | cleaned_data = self._remove_circular_references(self._config_data) |
| 59 | with self._config_path.open("w", encoding="utf-8") as f: |
| 60 | json.dump(cleaned_data, f, indent=4, ensure_ascii=False) |
| 61 | |
| 62 | def _remove_circular_references(self, obj, seen=None): |
| 63 | """递归移除循环引用""" |
no test coverage detected