Repository navigation
Conversation
Documentation build overview
12 files changed ·
|
| python_code="import os; print(os.process_cpu_count())" | ||
| ): | ||
| result = [ | ||
| "systemd-run", |
There was a problem hiding this comment.
I don't like this test. It changes systemd settings, even temporarily.
There was a problem hiding this comment.
It doesn't really change systemd settings. It creates a new scope: "The main purpose of scope units is grouping worker processes of a system service for organization and for managing resources." per the man page (https://www.freedesktop.org/software/systemd/man/latest/systemd.scope.html).
So this creates a new scope, with specific CPU quota just for those processes, in the scope, by creating a new cgroup.
So this is essentially like doing docker run: it runs a process under a new cgroup. But unlike Docker you don't have have to jump through hoops to access the host filesystem, so it's mechanically simpler.
There was a problem hiding this comment.
What I meant is that it still creates a transient systemd config. What about systems that aren't on systemd? I believe Alpine doesn't have systemd but alpine docker images are quite used right? (or maybe I misremember).
What I meant is: would it be possible to mock the result of open() instead without invoking systemd at all? And only skip the test when the files don't exist for instance (and also exercise the code paths where the file doesn't exist indeed or raises OSError)
There was a problem hiding this comment.
I think it's very useful to have end-to-end tests, when possible, otherwise it's easy to end up in a situation where the mocks/fakes diverge from reality.
But yeah there's the error paths too. And perhaps some CPython devs use non-systemd Linux, too, though CI at least will catch problems.
So maybe an additional set of mock/fake-based tests? And maybe the end-to-end test with systemd can be a bit smaller.
There was a problem hiding this comment.
What I meant is: would it be possible to mock the result of open() instead without invoking systemd at all?
Hum. If we decide to add tests mocking open(), I would still prefer to also have the systemd-run "integration tests". I already saw major bugs in code tested only by mocks. When you mock everything, you don't test the implementation anymore, but you test the mocks themselves :-D So the two kinds of tests are useful and have different purposes.
There was a problem hiding this comment.
I've added some more tests that talk to the underlying functions directly, and exercise the OSError paths. But I kept (most) of the end-to-end tests too. Let me know if there's more test coverage you want.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
|
||
| if sys.platform == "linux": | ||
| def _get_cgroup2_mount_point(): | ||
| from builtins import open |
There was a problem hiding this comment.
Why do you get use builtins.open() instead of open()?
There was a problem hiding this comment.
Cause open() gets masked by os.open().
| # Rounds up in order to saturate CPUs if the quota is fractional: | ||
| import math | ||
|
|
||
| return max(math.ceil(quota / period), 1) |
There was a problem hiding this comment.
You can avoid floating point numbers and math.ceil() code with:
| # Rounds up in order to saturate CPUs if the quota is fractional: | |
| import math | |
| return max(math.ceil(quota / period), 1) | |
| # Rounds up in order to saturate CPUs if the quota is fractional: | |
| count = (quota + (period - 1)) // period | |
| return max(count, 1) |
There was a problem hiding this comment.
I felt the float version was more readable, but can change if you want.
|
Thank you for the reviews! Will start addressing now. |
Co-authored-by: Victor Stinner <vstinner@python.org>
There are existing tests for this in |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @picnixz: please review the changes made to this pull request. |
Fixes #149452