Skip to content

Commit

Permalink
Fix threads parsing bugs
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 committed Oct 23, 2023
1 parent 62890e7 commit 4dd1591
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

Check warning on line 211 in piperider_cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/__init__.py#L211

Added line #L211 was not covered by tests

# 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:

Check warning on line 220 in piperider_cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/__init__.py#L219-L220

Added lines #L219 - L220 were not covered by tests
# fail to covert
raise

Check warning on line 222 in piperider_cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/__init__.py#L222

Added line #L222 was not covered by tests
# unknown cases
return var

Check warning on line 224 in piperider_cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/__init__.py#L224

Added line #L224 was not covered by tests

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

Check warning on line 119 in piperider_cli/datasource/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/datasource/__init__.py#L113-L119

Added lines #L113 - L119 were not covered by tests
elif engine and not isinstance(engine.pool, SingletonThreadPool):
return 5
else:
Expand Down

0 comments on commit 4dd1591

Please sign in to comment.