Miscs improvements (Interro02)
This commit is contained in:
@@ -85,6 +85,8 @@ def flush_thread_log(tid=None):
|
||||
# --- Lock for thread-safe file writing ---
|
||||
io_lock = threading.Lock()
|
||||
pro_lock = threading.Lock()
|
||||
group_index_lock = threading.Lock()
|
||||
reserved_group_indices: dict[str, int] = {}
|
||||
pro_count = 0
|
||||
flash_count = 0
|
||||
pro_quota_exhausted = False
|
||||
@@ -155,6 +157,7 @@ def configure_runtime(
|
||||
completed_tasks = []
|
||||
results = {label: [] for _file, label in tasks}
|
||||
thread_logs.clear()
|
||||
reserved_group_indices.clear()
|
||||
pro_count = 0
|
||||
flash_count = 0
|
||||
pro_quota_exhausted = False
|
||||
@@ -294,6 +297,16 @@ def get_next_group_idx(label):
|
||||
if not existing: return 0
|
||||
return max([int(f.stem.split("_")[1]) for f in existing])
|
||||
|
||||
|
||||
def reserve_next_group_idx(label: str) -> int:
|
||||
"""Reserve a unique zero-based group index for this correction run."""
|
||||
with group_index_lock:
|
||||
if label not in reserved_group_indices:
|
||||
reserved_group_indices[label] = get_next_group_idx(label)
|
||||
idx = reserved_group_indices[label]
|
||||
reserved_group_indices[label] = idx + 1
|
||||
return idx
|
||||
|
||||
def handle_label_errors(pid, label, res, pdf_path):
|
||||
"""Handles Gemini labeling errors, moves/copies files, and returns new tasks."""
|
||||
new_tasks = []
|
||||
@@ -334,7 +347,7 @@ def handle_label_errors(pid, label, res, pdf_path):
|
||||
if pdf_path != old_pdf_path:
|
||||
shutil.move(str(pdf_path), str(old_pdf_path))
|
||||
|
||||
idx = get_next_group_idx(new_label)
|
||||
idx = reserve_next_group_idx(new_label)
|
||||
height = grouping.get_pdf_height(str(new_pdf_path))
|
||||
grouping.create_jpg(new_label, idx, [(pid, str(new_pdf_path), height)], GROUPS_DIR)
|
||||
tprint(f"\t\tMaking {new_label} group {idx+1}")
|
||||
@@ -366,7 +379,7 @@ def handle_label_errors(pid, label, res, pdf_path):
|
||||
if not base_add_pdf_path.exists() and not add_pdf_path.exists():
|
||||
shutil.copy(str(pdf_path), str(add_pdf_path))
|
||||
tprint(f"\t\tCopying Copie{pid} : {label} -> {add_label}")
|
||||
idx = get_next_group_idx(add_label)
|
||||
idx = reserve_next_group_idx(add_label)
|
||||
tprint(f"\t\tMaking {add_label} group {idx+1}")
|
||||
height = grouping.get_pdf_height(str(add_pdf_path))
|
||||
grouping.create_jpg(add_label, idx, [(pid, str(add_pdf_path), height)], GROUPS_DIR)
|
||||
@@ -584,7 +597,7 @@ def resolve_delayed_moves():
|
||||
if pdf_path != old_pdf_path:
|
||||
shutil.move(str(pdf_path), str(old_pdf_path))
|
||||
|
||||
idx = get_next_group_idx(target_label)
|
||||
idx = reserve_next_group_idx(target_label)
|
||||
height = grouping.get_pdf_height(str(new_pdf_path))
|
||||
grouping.create_jpg(target_label, idx, [(pid, str(new_pdf_path), height)], GROUPS_DIR)
|
||||
new_tasks.append((str(GROUPS_DIR / target_label / f"Group_{idx+1}.jpg"), target_label, False))
|
||||
@@ -602,7 +615,7 @@ def resolve_delayed_moves():
|
||||
resolved_any = True
|
||||
|
||||
shutil.copy(str(pdf_path), str(add_pdf_path))
|
||||
idx = get_next_group_idx(target_label)
|
||||
idx = reserve_next_group_idx(target_label)
|
||||
height = grouping.get_pdf_height(str(add_pdf_path))
|
||||
grouping.create_jpg(target_label, idx, [(pid, str(add_pdf_path), height)], GROUPS_DIR)
|
||||
new_tasks.append((str(GROUPS_DIR / target_label / f"Group_{idx+1}.jpg"), target_label, False))
|
||||
@@ -688,7 +701,7 @@ def run_configured(args: argparse.Namespace) -> ExitCode:
|
||||
# pdf_path = copie_dir / f"{label}_old.pdf"
|
||||
|
||||
if pdf_path.exists():
|
||||
idx = get_next_group_idx(label)
|
||||
idx = reserve_next_group_idx(label)
|
||||
height = grouping.get_pdf_height(str(pdf_path))
|
||||
grouping.create_jpg(label, idx, [(pid, str(pdf_path), height)], GROUPS_DIR)
|
||||
new_group_path = str(GROUPS_DIR / label / f"Group_{idx+1}.jpg")
|
||||
|
||||
Reference in New Issue
Block a user