Skip to content
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

[Utility] add env_float utility into ray._private.ray_constants #47117

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
15 changes: 15 additions & 0 deletions python/ray/_private/ray_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ def env_integer(key, default):
return default


def env_float(key, default):
Copy link
Member

Choose a reason for hiding this comment

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

QQ: Any use cases where we set float in env_var?

Copy link
Contributor Author

@hongpeng-guo hongpeng-guo Aug 13, 2024

Choose a reason for hiding this comment

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

Good question! In some cases in runtime, it's better to use float numbers for timeout_values, especially when comparing them to real-time (float) values. Reading them as floats makes more sense in those scenarios.

if key in os.environ:
value = os.environ[key]
try:
return float(value)
except ValueError:
logger.debug(
f"Found {key} in environment, but value must "
f"be a float. Got: {value}. Returning "
f"provided default {default}."
)
return default
return default


def env_bool(key, default):
if key in os.environ:
return (
Expand Down