Skip to content

Fix Stop button with fullscreen experiments on Windows - #43

Open
SherlockChiang wants to merge 1 commit into
psychopy:devfrom
SherlockChiang:fix/windows-fullscreen-stop
Open

Fix Stop button with fullscreen experiments on Windows#43
SherlockChiang wants to merge 1 commit into
psychopy:devfrom
SherlockChiang:fix/windows-fullscreen-stop

Conversation

@SherlockChiang

@SherlockChiang SherlockChiang commented Jul 13, 2026

Copy link
Copy Markdown

Fixes psychopy/psychopy#7693.

Problem

On Windows, switching focus away from a fullscreen experiment can interrupt the Stop button click before wx emits EVT_BUTTON. The button visibly enters its pressed state, but the existing callback is not invoked and the experiment continues running.

During reproduction with an active fullscreen PsychoPy window, EVT_LEFT_DOWN was received but EVT_BUTTON was not.

Change

Bind the Runner Python Stop button to EVT_LEFT_DOWN on Windows so the existing stopTask() command runs before a fullscreen focus change can interrupt the click.

The button is disabled before calling stopTask() to prevent the corresponding mouse-up from invoking the command a second time. The existing EVT_BUTTON binding remains in place for keyboard activation and for other platforms.

This does not change Job, Popen.kill(), or process-tree termination behavior. Runner and experiments launched from Coder share this Stop path.

Automated tests

Environment:

  • Windows 11
  • Python 3.11
  • wxPython 4.2.5
  • PsychoPy dev / 2026.2 at ceafbd09a741efd81b83cd39acb3a86df6e53fc1
  • psychopy-app dev

Command:

$env:PYTHONPATH = 'C:\Users\vince\AppData\Local\Temp\opencode\psychopy-dev;src'
.venv\Scripts\python.exe -m pytest tests/test_runner.py tests/test_app.py -q

Result:

2 passed

The new unit test verifies that the Stop button is disabled before stopTask() is called, preventing re-entry while termination yields to the wx event loop. The existing app smoke test launches Builder, Runner, and Coder.

Additional checks:

.venv\Scripts\python.exe -m compileall -q src tests
git diff --check

Both completed successfully.

Windows end-to-end test flow

  1. Start a Python experiment through the same Job path used by Runner.
  2. Open a PsychoPy visual.Window and continuously call win.flip().
  3. Test once with fullscr=False and once with fullscr=True.
  4. Bring a wx Stop window to the foreground after the experiment starts.
  5. Use wx.UIActionSimulator to issue a real mouse-down and mouse-up over Stop.
  6. Route EVT_LEFT_DOWN through RunnerRibbon._stopOnMouseDown().
  7. Record EVT_LEFT_DOWN, EVT_BUTTON, the managed process state, and remaining processes.

Windowed result:

fullscr=False
LEFT_DOWN callback entered
terminated
running=False leftDown=1 button=0

Fullscreen result:

fullscr=True
LEFT_DOWN callback entered
terminated
running=False leftDown=1 button=0

In both modes the submitted handler ran, the experiment stopped, and no experiment process remained. The fullscreen result also reproduces the event-level cause: the mouse-down event arrives while the normal button event does not.

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.

[Bug]: Runner/Coder red "Stop" button fails to kill python process when a full-screen Window is active

1 participant