Skip to content
Snippets Groups Projects
Commit 74e2dd6c authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

refactor thanks to CodeClimate

parent 43421359
No related branches found
No related tags found
No related merge requests found
......@@ -186,18 +186,19 @@ def stringify(obj: tp.Union[tp.Any], stringifier: tp.Callable[[tp.Any], str] = s
:return: stringified object
"""
if isinstance(obj, str):
return obj
y = obj
elif isinstance(obj, enum.Enum):
return obj.name
y = obj.name
elif isinstance(obj, collections.abc.Mapping):
make_str = (lambda obj2: stringify(obj2, stringifier, True, str_none)) if recursively else \
stringifier
return {make_str(k): make_str(v) for k, v in obj.items()}
y = {make_str(k): make_str(v) for k, v in obj.items()}
elif isinstance(obj, collections.abc.Sequence):
make_str = (lambda obj2: stringify(obj2, stringifier, True, str_none)) if recursively else \
stringifier
return [make_str(v) for v in obj]
y = [make_str(v) for v in obj]
elif obj is None:
return _stringify_none(str_none, stringifier)
y = _stringify_none(str_none, stringifier)
else:
return stringifier(obj)
y = stringifier(obj)
return y
......@@ -108,25 +108,28 @@ def sleep_cpu_aware(seconds: tp.Union[str, float], of_below: tp.Optional[float]
:param check_each: amount of seconds to sleep at once
:return: whether was awoken due to CPU time condition
"""
v = False
if of_below is None and of_above is None:
time.sleep(seconds)
return False
calculate_occupancy_factor() # prime the counter
while seconds > 0:
time_to_sleep = min(seconds, check_each)
time.sleep(time_to_sleep)
of = calculate_occupancy_factor()
if of_above is not None:
if of > of_above:
return True
if of_below is not None:
if of < of_below:
return True
seconds -= time_to_sleep
if seconds <= 0:
return False
return False
else:
calculate_occupancy_factor() # prime the counter
while seconds > 0:
time_to_sleep = min(seconds, check_each)
time.sleep(time_to_sleep)
of = calculate_occupancy_factor()
if of_above is not None:
if of > of_above:
v = True
break
if of_below is not None:
if of < of_below:
v = True
break
seconds -= time_to_sleep
if seconds <= 0:
break
return v
previous_cf = None # type: float
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment