fix: resolve RAM default pid at init time - #1326
Open
davidberenstein1957 wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1326 +/- ##
=======================================
Coverage 91.43% 91.43%
=======================================
Files 49 49
Lines 5057 5058 +1
=======================================
+ Hits 4624 4625 +1
Misses 433 433 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The default `pid=psutil.Process().pid` was evaluated at import, so a forked child constructing `RAM()` recorded the parent's pid. In process tracking mode that meant measuring the parent and all its descendants, or reporting 0 W once the parent exited. Resolve the pid in `__init__` instead, so each instance measures the process that created it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
davidberenstein1957
force-pushed
the
fix/ram-default-pid
branch
from
August 20, 2026 06:14
eb4eada to
19fc243
Compare
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.
What
RAM.__init__tookpid: int = psutil.Process().pid. Python evaluates default arguments once at import, so the value was frozen to whichever process first importedcodecarbon.external.ram— and survivedfork(). The default is nowNone, resolved toos.getpid()inside__init__(matching howCPUalready does it inexternal/hardware.py).Why
Neither construction site passes a pid (
core/resource_tracker.py:37,core/hardware_cache.py:164), so the stale default was always in use. In a forked child withtracking_mode="process"this meant measuring the parent's RSS plus every sibling worker, or — if the parent had exited —NoSuchProcess, whichtotal_powerswallows into a silent 0 W for the rest of the run.Verification
New test
tests/test_ram.py::TestRAM::test_default_pid_is_resolved_in_forked_childforks a child, constructsRAM(tracking_mode="process")there and asserts_pidis the child's own pid. It fails on master and passes with this change;uv run pytest tests/test_ram.pyis green (21 passed).Closes #1318
🤖 Generated with Claude Code