From 16bd1a30cbef594f26c4daa7623814d7a14db915 Mon Sep 17 00:00:00 2001 From: "Ching Yi, Chan" Date: Mon, 23 Oct 2023 16:10:22 +0800 Subject: [PATCH] Fix threads parsing bugs Signed-off-by: Ching Yi, Chan Co-authored-by: wcchang --- piperider_cli/__init__.py | 20 +++++++++++++++++--- piperider_cli/datasource/__init__.py | 8 +++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/piperider_cli/__init__.py b/piperider_cli/__init__.py index 665c72c8b..3bf317da4 100644 --- a/piperider_cli/__init__.py +++ b/piperider_cli/__init__.py @@ -205,9 +205,23 @@ def as_bool(var): def as_number(var): if var is None: return var - if var.isnumeric(): - return int(var) - return float(var) + + # the input has been a numeric value + if isinstance(var, int) or isinstance(var, float): + return var + + # the input is str, but could convert to a numeric value + try: + if isinstance(var, str): + if var.isnumeric(): + return int(var) + else: + return float(var) + except BaseException: + # fail to covert + raise + # unknown cases + return var def as_text(var): if var is None: diff --git a/piperider_cli/datasource/__init__.py b/piperider_cli/datasource/__init__.py index 803f49be2..9c42f63ee 100644 --- a/piperider_cli/datasource/__init__.py +++ b/piperider_cli/datasource/__init__.py @@ -110,7 +110,13 @@ def threads(self): except Exception: engine = None if self.credential.get('threads'): - return self.credential.get('threads') + try: + return int(self.credential.get('threads')) + except BaseException as e: + console = Console() + message = 'failed to parse the "threads" field, so we will use 1 thread to execute profiling.' + console.print(f'[bold yellow]Warning: [/bold yellow]:\n {message}') + return 1 elif engine and not isinstance(engine.pool, SingletonThreadPool): return 5 else: