Skip to content

Process-tree sampling follow-ups: no GUI-process handle churn, bounded watchdog cache, one walk per tick - #172

Merged
jamesabel merged 1 commit into
masterfrom
review-followups-171
Aug 27, 2026
Merged

jamesabel merged 1 commit into
masterfrom
review-followups-171

Conversation

@jamesabel

Copy link
Copy Markdown
Owner

Follow-up to #171: the non-blocking findings from its review.

  • GUI-process handle churn (ensure windows that need scroll bars have them #5): _refresh_descendant_snapshot (runs every poll in the GUI process) built its (pid, create_time) snapshot via subtree_processes() — a psutil.Process construction per descendant per tick, the pattern Reuse cached psutil.Process handles across subtree samples #171 removed everywhere else. It now reads subtree_members(): same pairs, one snapshot, zero constructions. subtree_processes()'s docstring no longer claims a tree-kill caller it never had.
  • Unbounded watchdog cache (Add history DB #6): SubtreeCpuSampler.retain(root_pids) — the watchdog retains only the RUNNING pids each tick, so finished modules' root bundles no longer leak for the run's lifetime.
  • AccessDenied re-construction (New DB to keep track of the state of pytest processes #8): AccessDenied on cpu_percent()/memory_info() keeps the handle (not an identity failure); only NoSuchProcess drops it.
  • One walk per tick (Bump flask from 3.1.0 to 3.1.1 #10 remainder): ProcessMonitor computes subtree_members() once and hands it to both the CPU sampler and the commit read (sample()/subtree_commit() take an optional precomputed members).
  • Silent fallback: losing psutil._ppid_map now logs a one-shot warning.
  • Tests: tree teardown uses the production terminate_process_tree instead of a third copy of the kill helper; one test per change.

#7 (rejected descendants re-walked) and #9 (test equivalence) were already resolved by #171's blocking fixes.

Verified: full suite on Windows (517 passed); the handle-reuse module on Linux (WSL Ubuntu, py3.12, psutil 7.2.2).

Version 0.10.4.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PVCS61GzFRFktdBzn8xxce

…d watchdog cache, one walk per tick

The remaining (non-blocking) findings from the #171 review:

- _refresh_descendant_snapshot (GUI process, every poll) built its (pid, create_time)
  snapshot via subtree_processes(), constructing a psutil.Process per descendant per tick --
  the exact pattern the handle-reuse work removed elsewhere. It now reads subtree_members(),
  which yields those pairs from one snapshot with zero constructions. subtree_processes()'s
  docstring no longer claims a tree-kill caller it never had; it is the snapshot fallback.
- SubtreeCpuSampler.retain(root_pids): the stall watchdog's run-lifetime sampler only evicted
  inside sample(), so every finished module's root bundle (root handle, members, descendant
  handles) leaked until the runner was discarded. The watchdog now retains only the RUNNING
  pids each tick.
- AccessDenied on cpu_percent()/memory_info() no longer drops the handle (it is not an
  identity failure); a live-but-protected helper was being re-constructed every tick, in
  both the monitor child and the GUI-process watchdog. NoSuchProcess still drops.
- ProcessMonitor takes one subtree_members() walk per tick and hands it to both the CPU
  sampler and the commit read (sample()/subtree_commit() accept a precomputed members dict)
  instead of two full-system snapshots per tick that could disagree within one sample.
- Losing psutil's private _ppid_map now logs a one-shot warning instead of silently
  degrading to the handle-constructing walk.
- Tests: the handle-reuse module's tree teardown uses the production terminate_process_tree
  instead of a third copy of the kill helper; one test per change above.

Version 0.10.4.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PVCS61GzFRFktdBzn8xxce
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.75%. Comparing base (f5a1136) to head (ee3b91a).

Files with missing lines Patch % Lines
src/pytest_fly/pytest_runner/process_monitor.py 75.00% 4 Missing ⚠️
src/pytest_fly/pytest_runner/commit_memory.py 78.57% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #172      +/-   ##
==========================================
+ Coverage   85.72%   85.75%   +0.02%     
==========================================
  Files          74       74              
  Lines        6359     6379      +20     
==========================================
+ Hits         5451     5470      +19     
- Misses        908      909       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamesabel
jamesabel merged commit 1c29142 into master Aug 27, 2026
3 checks passed
@jamesabel
jamesabel deleted the review-followups-171 branch August 27, 2026 19:58
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.

2 participants