Skip to content

gh-99242 Catch OSError when calling getloadavg in libregrtest #106705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,10 @@ def getloadavg(self):
return self.win_load_tracker.getloadavg()

if hasattr(os, 'getloadavg'):
return os.getloadavg()[0]
try:
return os.getloadavg()[0]
except OSError:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The raised exception does not have any other information that .args == ('Load averages are unobtainable',), so it's ok if we don't inspect it more to make sure we're catching only the issue at hand.

pass

return None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`os.getloadavg` may throw :exc:`OSError` when running regression tests under
certain conditions (e.g. chroot). This error is now caught and ignored, since
reporting load average is optional.