Skip to content

fix: cast CPUTimeLeft as an int#8521

Open
aldbr wants to merge 2 commits intoDIRACGrid:integrationfrom
aldbr:fix-jobagent-cputime-int
Open

fix: cast CPUTimeLeft as an int#8521
aldbr wants to merge 2 commits intoDIRACGrid:integrationfrom
aldbr:fix-jobagent-cputime-int

Conversation

@aldbr
Copy link
Copy Markdown
Contributor

@aldbr aldbr commented Apr 24, 2026

BEGINRELEASENOTES
*WorkloadManagement
FIX: JobAgent cast CPUTimeLeft as an int
ENDRELEASENOTES

Most of the consumers are expecting an int (which makes sense actually).
Having that piece of code in the consumers:

cpuWorkLeft = gConfig.getValue("/LocalSite/CPUTimeLeft", 0)

Always results in 0, the default value.

Context: #8416

@aldbr aldbr requested review from atsareg and fstagni as code owners April 24, 2026 08:44
self._updateConfiguration("CPUTimeLeft", self.cpuWorkLeft)
# Store as int: consumers generally call gConfig.getValue(..., 0)
# with an int default, and a float-formatted value silently coerces to 0.
self._updateConfiguration("CPUTimeLeft", int(self.cpuWorkLeft))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you explain this a little more? I'm not seeing what this changes in practice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you want further explanations in the code comment or just an example here? Here is a very simple reproducer:

In [5]: print(gConfig.getValue("/Resources/Sites/LCG/<Site>/CEs/<CE>/Timeout", 0))
0

In [6]: print(gConfig.getValue("/Resources/Sites/LCG/<Site>/CEs/<CE>/Timeout", 0.0))
10.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indeed, I just mean an example here. So what happens is:

  • type(defaultValue) -> int
  • we have /Resources/.../Timeout = 10.0
  • int("10.0") -> ValueError
  • catch exception silently
  • return defaultValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants