fix(orchestrator): Ctrl+C hangs and threading shutdown traceback

Python ThreadPoolExecutor workers cannot be killed when blocked in HTTP
I/O. Previous approach of waiting for graceful cancellation via
shutdown(wait=True) caused infinite hangs, and re-raising KeyboardInterrupt
still triggered Python's _python_exit thread-join cleanup on exit.

Replace with hard-exit strategy: first Ctrl+C marks all unfinished books
(active + pending) as cancelled, prints summary, returns partial result
with interrupted=True. CLI then calls os._exit(130) to bypass thread
cleanup entirely. Second Ctrl+C hard-exits immediately.

Also fixes: books_with_index[idx][0] returning int index instead of
Book object (AttributeError on summary), empty CancelledError reason
strings, missing cancel_event wiring through download_book->download_m4b
call chain, and corrupted test body from earlier edit collision.

256 tests pass.
This commit is contained in:
AlexKucera committed 2026-06-04 13:10:10 +02:00
1 parent b7cae793df
commit 3dcae24d34
12 files changed
+835 -116

No files matched your search

+12
View File
@@ -37,6 +37,9 @@ class PlainTextReporter:
detail = f" ({reason})" if reason else ""
self._print(f"Failed: {authors} - {book.title} [{book.isbn}]{detail}")
def stop(self) -> None:
"""No-op for plain text mode — nothing to stop."""
def update(self, completed: int, *, total: int | None = None) -> None:
"""No-op progress update — plain text mode has no progress bar."""
@@ -148,6 +151,15 @@ class ProgressReporter:
kwargs["total"] = total
self._progress.update(task_id, **kwargs)
def stop(self) -> None:
"""Stop the live progress display.
Must be called before printing any output outside the progress system,
e.g. in KeyboardInterrupt/exception handlers, to prevent display corruption.
"""
if self._progress is not None:
self._progress.stop()
def complete(self, book) -> None:
"""Mark this book's progress bar as complete and remove it."""
task_id = self._book_ids.pop(id(book), None)