UI: Minor defensive changes to autosave

This commit is contained in:
oobabooga 2026-03-11 15:50:16 -07:00
parent bb00d96dc3
commit 980a9d1657
2 changed files with 13 additions and 6 deletions

View file

@ -6,6 +6,7 @@ import json
import pprint
import re
import shutil
import threading
import time
from datetime import datetime
from functools import partial
@ -40,6 +41,8 @@ from modules.utils import (
)
from modules.web_search import add_web_search_attachments
_history_file_lock = threading.Lock()
def strftime_now(format):
return datetime.now().strftime(format)
@ -1200,8 +1203,9 @@ def save_history(history, unique_id, character, mode):
if not p.parent.is_dir():
p.parent.mkdir(parents=True)
with open(p, 'w', encoding='utf-8') as f:
f.write(json.dumps(history, indent=4, ensure_ascii=False))
with _history_file_lock:
with open(p, 'w', encoding='utf-8') as f:
f.write(json.dumps(history, indent=4, ensure_ascii=False))
def rename_history(old_id, new_id, character, mode):