Repository navigation
Process-tree sampling follow-ups: no GUI-process handle churn, bounded watchdog cache, one walk per tick - #172
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #171: the non-blocking findings from its review.
_refresh_descendant_snapshot(runs every poll in the GUI process) built its(pid, create_time)snapshot viasubtree_processes()— apsutil.Processconstruction per descendant per tick, the pattern Reuse cached psutil.Process handles across subtree samples #171 removed everywhere else. It now readssubtree_members(): same pairs, one snapshot, zero constructions.subtree_processes()'s docstring no longer claims a tree-kill caller it never had.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.AccessDeniedre-construction (New DB to keep track of the state of pytest processes #8):AccessDeniedoncpu_percent()/memory_info()keeps the handle (not an identity failure); onlyNoSuchProcessdrops it.ProcessMonitorcomputessubtree_members()once and hands it to both the CPU sampler and the commit read (sample()/subtree_commit()take an optional precomputedmembers).psutil._ppid_mapnow logs a one-shot warning.terminate_process_treeinstead 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