Step 02 tool use
Now I can see the issue. Looking at the `_query_cpu` function (lines 34-60):
When `cpu_quota` is `-1`, the first `if` condition at line 47 (`cpu_quota and cpu_quota != -1`) evaluates to `False` (because `-1` is truthy but the second condition fails). So it falls through to the `elif` at line 56, which checks for `/sys/fs/cgroup/cpu/cpu.shares`.
In the user's case:
- `cpu_quota` = -1
- `cpu_shares` = 2
- `avail_cpu = int(2 / 1024)` = `int(0.00195...)` = 0
So `_query_cpu()` returns 0. Then in `_cpu_count()`:
- `cpu_share` = 0 (which is not None, so `if cpu_share is not None:` is True)
- It returns `min(0, cpu_count)` which is 0.
Then in `Run.__init__`, `linter.config.jobs` gets set to 0, and then `check_parallel` is called with `jobs=0`, which crashes when creating `multiprocessing.Pool`.
The fix should ensure that `_query_cpu` never returns 0. There are two possible issues:
1. `cpu_quota` being -1 (truthy but explicitly checked for -1) - this is fine, it falls through to the `cpu.shares` path.
2. The `cpu.shares` value could be very small (like 2) leading to `int(2/1024)` = 0.
Also, the first path could potentially return 0 if `cpu_quota` is less than `cpu_period`, e.g., `cpu_quota=50000, cpu_period=100000` → `int(50000/100000)` = 0.
The fix should ensure the result is at least 1. Let me look at both paths:
For the `cpu_quota / cpu_period` path: if quota < period, the result could be 0.
For the `cpu_shares / 1024` path: if shares < 1024, the result could be 0.
The user suggests appending `or 1`. But I think a cleaner approach would be to `max(avail_cpu, 1)` after computing it, or to check if avail_cpu is 0 and set it to 1.
Actually, looking more carefully, the issue is that `_query_cpu` can return 0, which then becomes the `cpu_share` value in `_cpu_count`. Since `0 is not None`, the condition `if cpu_share is not None:` is True, and `min(0, cpu_count)` returns 0.
The fix should be in `_query_cpu` to ensure we never return 0. We could add `max(avail_cpu, 1)` when avail_cpu is computed, or we could change `_cpu_count` to handle 0 as if it were None.
I think the cleanest fix is to ensure `avail_cpu` is at least 1 in `_query_cpu`, since a return of 0 is meaningless (you always need at least 1 CPU to run). Let me fix this.
I can see the bug. In `_query_cpu()`, when `cpu_quota` is `-1` (as in many container environments like Kubernetes), it falls through to the `cpu.shares` path. With `cpu_shares = 2`, the calculation `int(2 / 1024)` returns `0`, which causes `multiprocessing.Pool` to crash since it requires at least 1 process.
The same issue could theoretically happen in the `cpu_quota / cpu_period` path if quota < period. The fix is to ensure `_query_cpu()` never returns `0`:
edit_file{ path: "pylint/lint/run.py", old_string: " if (\n cpu_quota\n and cpu_quota != -1\n and Path(\"/sys/fs/cgroup/cpu/cpu.cfs_period_us\").is_file()\n ):\n with open(\"/sys/fs/cgro…", new_string: " if (\n cpu_quota\n and cpu_quota != -1\n and Path(\"/sys/fs/cgroup/cpu/cpu.cfs_period_us\").is_file()\n ):\n with open(\"/sys/fs/cgro…" }
tool result · edit_file
File pylint/lint/run.py edited successfully.