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

+8
View File
@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- **orchestrator:** Fix Ctrl+C hangs and threading shutdown traceback.
Python threads cannot be killed when blocked in HTTP I/O; previous approach
of `shutdown(wait=True)` caused infinite hangs. Now uses `os._exit(130)`
hard exit after printing summary, marks unfinished books as cancelled, and
bypasses Python's thread-pool cleanup entirely. Wires `cancel_event`
through full download stack (cli → orchestrator → download_book → download_m4b).
Fixes `books_with_index[idx][0]` bug that returned int index instead of Book
object in post-interrupt collection. 256 tests pass.
- **cli:** Remove redundant per-book verbose print in parallel download loop.
Progress bars already show author+title; the extra `⬇ title`/authors/narrators
block caused a triple-display (bars → details → live progress). 247 tests pass.