Skip to content

Every Stop freezes the window for about 1 s and loses track of the click thread #145

Closed

Description

@TMHSDigital

Summary

Stopping from the UI joins the click thread on the Tk main thread, while the click thread's finally calls back into Tk. The two wait on each other until the 1 s join timeout, then the engine forgets a thread that is still alive.

Where

  • autoclicker/core/click_engine.py:409-424 (_join_click_thread, stop_clicking)
  • autoclicker/core/click_engine.py:524-533 (finally calls on_finished)
  • autoclicker/app/controller.py:340-347
  • autoclicker/gui/main_window.py:730, :757-762
  • autoclicker/core/recorder.py:141 (same pattern: 2 s join on the UI thread)

Details

UI Stop runs AutoclickerApp.stop_clicking -> controller.stop_clicking -> engine.stop_clicking -> thread.join(timeout=1.0) on the Tk thread. The click thread wakes and its finally calls on_finished, which reaches self._ui(...) and root.after(0, ...). With threaded Tcl that call blocks until the Tk thread services it, which it cannot while it is inside join. A standalone repro with a withdrawn Tk root measured join took 1.018s, thread alive after join: True. _join_click_thread then sets click_thread = None although the thread is alive, which defeats the click_thread.is_alive() busy check in start_clicking for that window.

Impact

About 1 s of "Not responding" on every Stop (button, Stop or Toggle hotkey, tray Stop) and on Quit during a run. While it lasts the hotkey thread is also blocked, so Esc is not handled. The stop_clicking contract in docs/ARCHITECTURE.md ("joins click thread") never holds on the GUI path.

Steps to reproduce

  1. Start a run
  2. Press the Stop button
  3. The window stops responding for about a second

Suggested fix

On the GUI path, signal the stop without joining and let _on_run_finished -> finish_run reap the thread after the callback has run. Alternatively make _ui non-blocking (queue drained by a Tk after poll). In either case do not set click_thread = None when the join timed out with the thread still alive.

Acceptance criteria

  • Stop returns control to the UI in well under 100 ms
  • click_thread is only cleared once the thread has exited
  • Recorder stop does not block the UI thread on the hook thread

Getting started

  • Relevant files: autoclicker/core/click_engine.py, autoclicker/app/controller.py, autoclicker/gui/main_window.py
  • How to run tests: make check (Git Bash) or tasks.bat lint, tasks.bat typecheck, tasks.bat test (cmd). Single test: python -m pytest tests/test_x.py::TestClass::test_name --no-cov
  • Related docs: CONTRIBUTING.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 9968dc8. Severity: medium. Effort: S. audit-key: bug|autoclicker/core/click_engine.py|ClickEngine._join_click_thread

Activity

  1. added
    bug
    priority: medium
    on Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugpriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions