Skip to content

Commit

Permalink
Fix threads parsing bugs (#909)
Browse files Browse the repository at this point in the history
Signed-off-by: Ching Yi, Chan <qrtt1@infuseai.io>
Co-authored-by: wcchang <wcchang@infuseai.io>
  • Loading branch information
qrtt1 and wcchang1115 authored Oct 23, 2023
1 parent 62890e7 commit ae7f51c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 17 additions & 3 deletions piperider_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion piperider_cli/datasource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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:
Expand Down

0 comments on commit ae7f51c

Please sign in to comment.