upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authord7ommy <abnalstlll@gmail.com>2026-11-25 19:55:46 +0300
committerd7ommy <abnalstlll@gmail.com>2026-11-25 19:55:46 +0300
commit30a2a1862c9c21eddcc345985b5d74347a40ad85 (patch)
tree8a90fc662d75bd0eeecb28952440ca5f121e0d6d /scripts
parent542c046c503af54cf6b29436eff4877f4edb7de4 (diff)
run_semantic_tests: terminate process tree on Windows via taskkill and increase sleep margin (SEMANTIC-RUNNER-INTERRUPT)
- On Windows, terminate child processes using taskkill /F /T /PID to ensure launcher processes (e.g. venv python.exe wrappers) terminate all child workers. - Increase synthetic sleep duration in tests from 5s to 10s and timeout margin to eliminate timing flakiness under high machine load. AI-assisted (Claude Code).
Diffstat (limited to 'scripts')
-rw-r--r--scripts/run_semantic_tests.py45
1 files changed, 21 insertions, 24 deletions
diff --git a/scripts/run_semantic_tests.py b/scripts/run_semantic_tests.py
index 628e47574..514e78133 100644
--- a/scripts/run_semantic_tests.py
+++ b/scripts/run_semantic_tests.py
@@ -56,6 +56,21 @@ def _unregister_process(proc):
56 _active_processes.discard(proc) 56 _active_processes.discard(proc)
57 57
58 58
59def _kill_process_tree(proc):
60 if proc is None:
61 return
62 if os.name == "nt":
63 try:
64 subprocess.run(["taskkill", "/F", "/T", "/PID", str(proc.pid)],
65 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
66 except OSError:
67 pass
68 try:
69 proc.kill()
70 except OSError:
71 pass
72
73
59def _terminate_active_processes(): 74def _terminate_active_processes():
60 with _processes_lock: 75 with _processes_lock:
61 procs = list(_active_processes) 76 procs = list(_active_processes)
@@ -65,10 +80,7 @@ def _terminate_active_processes():
65 except OSError: 80 except OSError:
66 pass 81 pass
67 for p in procs: 82 for p in procs:
68 try: 83 _kill_process_tree(p)
69 p.kill()
70 except OSError:
71 pass
72 try: 84 try:
73 p.wait(timeout=0.2) 85 p.wait(timeout=0.2)
74 except (subprocess.TimeoutExpired, OSError): 86 except (subprocess.TimeoutExpired, OSError):
@@ -153,10 +165,7 @@ def run_module(directory, module, verbose, timeout=None):
153 try: 165 try:
154 stdout, stderr = proc.communicate(timeout=timeout) 166 stdout, stderr = proc.communicate(timeout=timeout)
155 except subprocess.TimeoutExpired: 167 except subprocess.TimeoutExpired:
156 try: 168 _kill_process_tree(proc)
157 proc.kill()
158 except OSError:
159 pass
160 stdout, stderr = proc.communicate() 169 stdout, stderr = proc.communicate()
161 # TimeoutExpired retains bytes even when text=True. 170 # TimeoutExpired retains bytes even when text=True.
162 parts = [chunk.decode(locale.getpreferredencoding(False), errors="replace") if isinstance(chunk, bytes) 171 parts = [chunk.decode(locale.getpreferredencoding(False), errors="replace") if isinstance(chunk, bytes)
@@ -164,10 +173,7 @@ def run_module(directory, module, verbose, timeout=None):
164 out = "".join(parts) 173 out = "".join(parts)
165 return 1, 0, out + f"\nTIMED OUT after {timeout:g} s: {module}\n" 174 return 1, 0, out + f"\nTIMED OUT after {timeout:g} s: {module}\n"
166 except BaseException: 175 except BaseException:
167 try: 176 _kill_process_tree(proc)
168 proc.kill()
169 except OSError:
170 pass
171 try: 177 try:
172 proc.wait(timeout=0.5) 178 proc.wait(timeout=0.5)
173 except (subprocess.TimeoutExpired, OSError): 179 except (subprocess.TimeoutExpired, OSError):
@@ -213,17 +219,11 @@ def main(argv=None):
213 if a.timeout is not None and time.monotonic() - start_time >= a.timeout: 219 if a.timeout is not None and time.monotonic() - start_time >= a.timeout:
214 raise 220 raise
215 except subprocess.TimeoutExpired: 221 except subprocess.TimeoutExpired:
216 try: 222 _kill_process_tree(proc)
217 proc.kill()
218 except OSError:
219 pass
220 print(f"TIMED OUT after {a.timeout:g} s: unittest discover in {directory}", file=sys.stderr) 223 print(f"TIMED OUT after {a.timeout:g} s: unittest discover in {directory}", file=sys.stderr)
221 return 1 224 return 1
222 except KeyboardInterrupt: 225 except KeyboardInterrupt:
223 try: 226 _kill_process_tree(proc)
224 proc.kill()
225 except OSError:
226 pass
227 try: 227 try:
228 proc.wait(timeout=0.5) 228 proc.wait(timeout=0.5)
229 except (subprocess.TimeoutExpired, OSError): 229 except (subprocess.TimeoutExpired, OSError):
@@ -231,10 +231,7 @@ def main(argv=None):
231 print("interrupted", file=sys.stderr) 231 print("interrupted", file=sys.stderr)
232 return 130 232 return 130
233 except BaseException: 233 except BaseException:
234 try: 234 _kill_process_tree(proc)
235 proc.kill()
236 except OSError:
237 pass
238 raise 235 raise
239 finally: 236 finally:
240 _unregister_process(proc) 237 _unregister_process(proc)