test_auto_restart_subprocess_termination[True] leaks a ProcessWatcher thread on macOS
tests/test_0_watchmedo.py::test_auto_restart_subprocess_termination[True] fails in teardown on macOS:
ERROR ...::test_auto_restart_subprocess_termination[True] - assert 2 == 1
tests/conftest.py:32: assert threading.active_count() == old_thread_count14 occurrences between 2026-08-15 and 2026-09-22, across macOS 3.9/3.10/3.12/3.13/3.14/3.14t/3.15. It fires on master pushes, not only PR branches: job 100259898057 on d9f0f52e, plus 96413541901 and 94988373750. No Linux or Windows job hit it in the same sample.
Not #972: that xfail is attached only to the False param, and True carries no marker.
AutoRestartTrick.stop() captures self.process_watcher into a local at tricks/__init__.py:247 and joins that reference at :256. With restart_on_command_exit=True, _restart_process runs on the watcher thread and _start_process assigns a fresh ProcessWatcher at :272. Its guard at :259 reads self._is_trick_stopping without _stopping_lock, while stop() sets it under that lock at :245, so a watcher started in that window is never joined.
That last part is read off the source, not instrumented. I am on Windows and cannot reproduce it locally.
Source: gorakhargosh/watchdog