Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

count_cpus() and RAM crash with FileNotFoundError when SLURM_JOB_ID is set but scontrol is missing

オープン 初心者向け
#1,455 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
83/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

codecarbon/core/util.py の count_cpus() と codecarbon/external/ram.py の RAM._read_slurm_scontrol() から始め、既存の CalledProcessError のフォールバック処理を調べてください。scontrol がない各ケースのテストを追加し、どちらも警告を出してマシンの CPU 数または RAM の総量にフォールバックすることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

Problem

count_cpus() (codecarbon/core/util.py) and RAM._read_slurm_scontrol() (codecarbon/external/ram.py) only catch subprocess.CalledProcessError. When SLURM_JOB_ID is set but the scontrol binary is not on PATH, subprocess.check_output raises FileNotFoundError instead, which is not caught.

This happens for example when a job runs inside a container (Docker / Apptainer) launched by SLURM: the SLURM env vars propagate but the SLURM client tools are not installed. The tracker then records no emissions and tracker.stop() returns None.

Reproduction

SLURM_JOB_ID=123 python -c "from codecarbon.core.util import count_cpus; count_cpus()"
# FileNotFoundError: [Errno 2] No such file or directory: 'scontrol'

Expected

Fall back to the machine's CPU count / total RAM with a warning, the same way the existing CalledProcessError path does.

Proposed fix

Catch (subprocess.CalledProcessError, FileNotFoundError) in both places and add a test for each. Happy to open a PR.

主要言語
Python
スター
1.9k
フォーク
347
平均マージ
2日 13時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

mlco2/codecarbon のほかの issue

mlco2/codecarbon の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。