Skip to content

Fix: after a reopen, is_alive() was False while reading and join() didn't wait - #4

Merged
thorwhalen merged 1 commit into
masterfrom
fix/thread-api-follows-current-worker
Sep 22, 2026
Merged

thorwhalen merged 1 commit into
masterfrom
fix/thread-api-follows-current-worker

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Post-merge refute review of #3.

Defect: #3 runs the first open() in self (the reader is a Thread) and every later one in a fresh threading.Thread. After a reopen, the inherited reader.is_alive() describes the finished first-run thread, so it is False while the reader is busy producing. reader.join() then returns immediately instead of waiting for the worker. The existing test test_stop_does_not_shadow_thread_internals shows close(); join(); assert not is_alive() is the intended usage, and that pattern silently stops meaning anything after the first cycle. #3's docstring claimed the Thread API kept behaving as before.

Fix: every open() starts its own worker thread, and is_alive()/join() follow the current worker. A reader started the legacy way, with start() instead of open(), has no worker and falls back to Thread's own. Running the first open in a fresh thread too, rather than in self, is what keeps #3's test_reopen_does_not_leak_worker_threads valid unchanged: _worker objects are distinct threads with accurate liveness.

Test: test_thread_api_follows_the_current_worker_after_reopen. It fails on master and passes here. All 6 tests pass (3 runs, py3.10).

Self-reviewed only (the dispatching run disallowed sub-agents).

🤖 Generated with Claude Code

#3 ran the first open() in self and later ones in fresh threads, so after a
reopen reader.is_alive() was False while the reader was reading and
reader.join() returned at once. Every open() now gets its own worker thread
and is_alive/join follow it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit 6e9b935 into master Sep 22, 2026
7 checks passed
@thorwhalen
thorwhalen deleted the fix/thread-api-follows-current-worker branch September 22, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant