From 3ba45eef0c63369b3996982613eaea9b0ebc5cdc Mon Sep 17 00:00:00 2001 From: Hongpeng Guo Date: Tue, 13 Aug 2024 13:03:57 -0700 Subject: [PATCH] add env_float unility Signed-off-by: Hongpeng Guo --- python/ray/_private/ray_constants.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/ray/_private/ray_constants.py b/python/ray/_private/ray_constants.py index 9e76e57e3088..b8b6f7b443a5 100644 --- a/python/ray/_private/ray_constants.py +++ b/python/ray/_private/ray_constants.py @@ -23,6 +23,21 @@ def env_integer(key, default): return default +def env_float(key, default): + 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 (