Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
74e2dd6c
Commit
74e2dd6c
authored
3 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
refactor thanks to CodeClimate
parent
43421359
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
satella/coding/transforms/__init__.py
+7
-6
7 additions, 6 deletions
satella/coding/transforms/__init__.py
satella/instrumentation/cpu_time/collector.py
+20
-17
20 additions, 17 deletions
satella/instrumentation/cpu_time/collector.py
with
27 additions
and
23 deletions
satella/coding/transforms/__init__.py
+
7
−
6
View file @
74e2dd6c
...
...
@@ -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
This diff is collapsed.
Click to expand it.
satella/instrumentation/cpu_time/collector.py
+
20
−
17
View file @
74e2dd6c
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment