comicbox.process ¶
Parallel processing for large-scale comic metadata reading.
ReadResult ¶
Bases: TypedDict
Result of reading metadata from a single comic archive.
The envelope fields (metadata_mtime, page_count, file_type) are populated cheaply on every successful read and are the source of truth for archive-level state tracking. tags carries the parsed metadata payload and is None when extraction was skipped — either because the embedded metadata mtime hadn’t advanced past old_mtime or because the caller passed full_metadata=False.
Distinguishing “skip” from “extracted-but-empty” is the contract that lets callers preserve existing tag links when the archive’s tags haven’t changed; an empty {} would mean “extracted, no tags found”, which would force the caller to clear those links.
Source code in comicbox/process.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
aread_metadata(path, config=None, fmt=MetadataFormats.COMICBOX_YAML) async ¶
Read metadata from a single comic file in a thread executor.
Source code in comicbox/process.py
372 373 374 375 376 377 378 379 | |
iter_process_files(paths, config=None, logger=None, fmt=MetadataFormats.COMICBOX_YAML, max_workers=None, old_mtime_map=None, worker_log_config=None, *, full_metadata=True, on_event=None) ¶
Yield (path, (ReadResult, exception_or_None)) as each file completes.
All per-path failures — submit-time, worker-raised, or pool-broken — are delivered as the second element of the tuple rather than raised, so a single bad path cannot abort the whole run. On failure the ReadResult is the empty sentinel (all fields None); inspect the exception, not the result, to detect failure.
worker_log_config: optional dict of {"level", "format", "sink"} used to re-initialize loguru inside each worker so subprocess log output matches the caller’s format. Must be picklable; pass sink as "stdout" / "stderr" / path string, not a file object.
on_event: optional handler invoked on the orchestrator thread with each :class:comicbox.events.Event. Fires :class:BatchStarted once before the first submit, one of :class:FileParsed / :class:FileShortCircuited / :class:FileError per delivered result, and :class:BatchFinished once with totals. Handler runs on the orchestrator thread and must be thread-safe and quick.
Source code in comicbox/process.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
process_files(paths, config=None, logger=None, fmt=MetadataFormats.COMICBOX_YAML, max_workers=None, worker_log_config=None, *, on_event=None) ¶
Process multiple comic files in parallel via ProcessPoolExecutor.
Source code in comicbox/process.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |