[PR #1936] [MERGED] run_semantic_tests: stop active subprocesses and cancel queued modules on interrupt (SEMANTIC-RUNNER-INTERRUPT) #1942

Closed
opened 2026-11-26 21:19:29 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1936
Author: @abnalstlll-byte
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: feat/semantic-runner-interrupt


📝 Commits (2)

  • 542c046 run_semantic_tests: stop active subprocesses and cancel queued modules on interrupt (SEMANTIC-RUNNER-INTERRUPT)
  • 30a2a18 run_semantic_tests: terminate process tree on Windows via taskkill and increase sleep margin (SEMANTIC-RUNNER-INTERRUPT)

📊 Changes

2 files changed (+261 additions, -21 deletions)

View changed files

📝 scripts/run_semantic_tests.py (+134 -21)
📝 tests/test_run_semantic_tests.py (+127 -0)

📄 Description

Summary

In scripts/run_semantic_tests.py, catch KeyboardInterrupt during both parallel module execution and serial test execution, cancelling queued test modules via pool.shutdown(wait=False, cancel_futures=True) and terminating active child subprocesses so that no orphaned zombie processes or queued modules run after Ctrl+C.

Changes

  • Active Subprocess Tracking: Track active child subprocesses in _active_processes with a thread-safe lock; register before execution and unregister upon completion.
  • Immediate Termination: On KeyboardInterrupt (or BaseException), invoke _terminate_active_processes() which terminates and kills registered child processes and cleans up immediately.
  • Future Cancellation: Empty remaining queued futures from ThreadPoolExecutor with pool.shutdown(wait=False, cancel_futures=True) and cancel all uncompleted futures so no pending tests run.
  • Responsive Wait Loop: In parallel execution, poll with concurrent.futures.wait(pending, timeout=0.2, return_when=FIRST_COMPLETED) to ensure sub-second signal delivery across Windows and POSIX.
  • Serial Mode: In -j 1 mode, run discover subprocess with responsive proc.wait(timeout=0.2) polling and clean interrupt termination.
  • Exit Code & Output: Return exit code 130 and output 'interrupted' to sys.stderr without printing a false success summary.
  • Regressions: Add parallel cancellation, serial interrupt, direct process termination, and POSIX signal regression tests in tests/test_run_semantic_tests.py.

Item: SEMANTIC-RUNNER-INTERRUPT

AI-assisted (Claude Code)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1936 **Author:** [@abnalstlll-byte](https://github.com/abnalstlll-byte) **Created:** 11/25/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `feat/semantic-runner-interrupt` --- ### 📝 Commits (2) - [`542c046`](https://github.com/ubiquitarianism/leonida/commit/542c046c503af54cf6b29436eff4877f4edb7de4) run_semantic_tests: stop active subprocesses and cancel queued modules on interrupt (SEMANTIC-RUNNER-INTERRUPT) - [`30a2a18`](https://github.com/ubiquitarianism/leonida/commit/30a2a1862c9c21eddcc345985b5d74347a40ad85) run_semantic_tests: terminate process tree on Windows via taskkill and increase sleep margin (SEMANTIC-RUNNER-INTERRUPT) ### 📊 Changes **2 files changed** (+261 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `scripts/run_semantic_tests.py` (+134 -21) 📝 `tests/test_run_semantic_tests.py` (+127 -0) </details> ### 📄 Description ### Summary In `scripts/run_semantic_tests.py`, catch `KeyboardInterrupt` during both parallel module execution and serial test execution, cancelling queued test modules via `pool.shutdown(wait=False, cancel_futures=True)` and terminating active child subprocesses so that no orphaned zombie processes or queued modules run after Ctrl+C. ### Changes - **Active Subprocess Tracking**: Track active child subprocesses in `_active_processes` with a thread-safe lock; register before execution and unregister upon completion. - **Immediate Termination**: On `KeyboardInterrupt` (or `BaseException`), invoke `_terminate_active_processes()` which terminates and kills registered child processes and cleans up immediately. - **Future Cancellation**: Empty remaining queued futures from `ThreadPoolExecutor` with `pool.shutdown(wait=False, cancel_futures=True)` and cancel all uncompleted futures so no pending tests run. - **Responsive Wait Loop**: In parallel execution, poll with `concurrent.futures.wait(pending, timeout=0.2, return_when=FIRST_COMPLETED)` to ensure sub-second signal delivery across Windows and POSIX. - **Serial Mode**: In `-j 1` mode, run discover subprocess with responsive `proc.wait(timeout=0.2)` polling and clean interrupt termination. - **Exit Code & Output**: Return exit code 130 and output `'interrupted'` to `sys.stderr` without printing a false success summary. - **Regressions**: Add parallel cancellation, serial interrupt, direct process termination, and POSIX signal regression tests in `tests/test_run_semantic_tests.py`. Item: `SEMANTIC-RUNNER-INTERRUPT` AI-assisted (Claude Code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:19:29 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1942
No description provided.