Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
95438d66
Commit
95438d66
authored
Oct 23, 2014
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix backward compatibility of niceness handling on non-Windows
parent
2db76474
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
10 deletions
+17
-10
__init__.py
printrun/power/__init__.py
+17
-10
No files found.
printrun/power/__init__.py
View file @
95438d66
...
@@ -77,6 +77,20 @@ else:
...
@@ -77,6 +77,20 @@ else:
try
:
try
:
import
psutil
import
psutil
def
get_nice
(
nice
,
p
=
None
):
if
not
p
:
p
=
psutil
.
Process
(
os
.
getpid
())
if
callable
(
p
.
nice
):
return
p
.
nice
()
else
:
return
p
.
nice
def
set_nice
(
nice
,
p
=
None
):
if
not
p
:
p
=
psutil
.
Process
(
os
.
getpid
())
if
callable
(
p
.
nice
):
p
.
nice
(
nice
)
else
:
p
.
nice
=
nice
if
platform
.
system
()
!=
"Windows"
:
if
platform
.
system
()
!=
"Windows"
:
import
resource
import
resource
if
hasattr
(
psutil
,
"RLIMIT_NICE"
):
if
hasattr
(
psutil
,
"RLIMIT_NICE"
):
...
@@ -87,22 +101,15 @@ try:
...
@@ -87,22 +101,15 @@ try:
# RLIMIT_NICE is not available (probably OSX), let's probe
# RLIMIT_NICE is not available (probably OSX), let's probe
# Try setting niceness to -20 .. -1
# Try setting niceness to -20 .. -1
p
=
psutil
.
Process
(
os
.
getpid
())
p
=
psutil
.
Process
(
os
.
getpid
())
orig_nice
=
p
.
get_nice
(
)
orig_nice
=
get_nice
(
p
)
for
i
in
range
(
-
20
,
0
):
for
i
in
range
(
-
20
,
0
):
try
:
try
:
p
.
set_nice
(
i
)
set_nice
(
i
,
p
)
high_priority_nice
=
i
high_priority_nice
=
i
break
break
except
psutil
.
AccessDenied
,
e
:
except
psutil
.
AccessDenied
,
e
:
pass
pass
p
.
set_nice
(
orig_nice
)
set_nice
(
orig_nice
,
p
)
def
set_nice
(
nice
):
p
=
psutil
.
Process
(
os
.
getpid
())
if
callable
(
p
.
nice
):
p
.
nice
(
nice
)
else
:
p
.
nice
=
nice
def
set_priority
():
def
set_priority
():
if
platform
.
system
()
==
"Windows"
:
if
platform
.
system
()
==
"Windows"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment