Skip to content

Fix Windows timer thread shutdown (#991)#1012

Merged
emeryberger merged 1 commit intomasterfrom
fix/windows-timer-thread-shutdown
Mar 4, 2026
Merged

Fix Windows timer thread shutdown (#991)#1012
emeryberger merged 1 commit intomasterfrom
fix/windows-timer-thread-shutdown

Conversation

@emeryberger
Copy link
Member

Summary

  • Replace time.sleep() with threading.Event.wait() in Windows timer and memory polling threads so stop_timer_thread() / stop_windows_memory_polling() can interrupt sleeping threads immediately
  • Increase timer thread join timeout from 0.1s to 2.0s as a safety margin
  • Make the initial 10ms startup delay also interruptible

Fixes the gilstate_tss_set fatal error reported in #991 — the non-daemon timer thread was surviving past join() timeout and calling into Python during interpreter finalization.

Test plan

  • All 319 existing tests pass (python3 -m pytest tests/ -v)
  • Manual verification on Windows that profiling completes without gilstate_tss_set error
  • Verify no PythonTracer::stop() warning from PyTorch on shutdown

🤖 Generated with Claude Code

Replace time.sleep() with threading.Event.wait() in the Windows timer
and memory polling threads so they can be interrupted immediately on
shutdown. Previously, stop_timer_thread() would time out after 0.1s
because the sleeping thread couldn't check the stop flag, leaving a
non-daemon thread alive during interpreter finalization.

Fixes #991

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@emeryberger emeryberger merged commit 1fa9b41 into master Mar 4, 2026
52 of 64 checks passed
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