aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLumir Balhar <lbalhar@redhat.com>2017-11-09 14:48:04 +0100
committerJiri Kastner <jkastner@redhat.com>2017-11-20 13:53:13 +0100
commit76cbbd195fbd57cbea4a871b52c0747a1822ee11 (patch)
tree057332d52b606eb0cb615f7c3372fe0a75538cee
parent479dd04253a72161cf4f3fb28128492f9a7daa2a (diff)
downloadpython-schedutils-76cbbd195fbd57cbea4a871b52c0747a1822ee11.tar.gz
python3: Fix incompatible prints and exceptions
Signed-off-by: Lumir Balhar <lbalhar@redhat.com> Signed-off-by: Jiri Kastner <jkastner@redhat.com>
-rwxr-xr-xpchrt.py22
-rwxr-xr-xptaskset.py15
2 files changed, 20 insertions, 17 deletions
diff --git a/pchrt.py b/pchrt.py
index c590b37..ddb1265 100755
--- a/pchrt.py
+++ b/pchrt.py
@@ -14,13 +14,14 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
+from __future__ import print_function
import os
import schedutils
import sys
def usage():
- print '''pchrt (python-schedutils)
+ print('''pchrt (python-schedutils)
usage: pchrt [options] [prio] [pid | cmd [args...]]
manipulate real-time attributes of a process
-b, --batch set policy to SCHED_BATCH
@@ -35,16 +36,16 @@ manipulate real-time attributes of a process
You must give a priority if changing policy.
-Report bugs and send patches to <tuna-devel@lists.fedorahosted.org>'''
+Report bugs and send patches to <tuna-devel@lists.fedorahosted.org>''')
return
def show_priority_limits(policy):
- print "%-32.32s: %d/%d" % (
+ print("%-32.32s: %d/%d" % (
"%s min/max priority" % schedutils.schedstr(policy),
schedutils.get_priority_min(policy),
schedutils.get_priority_max(policy)
- )
+ ))
def show_all_priority_limits():
@@ -60,14 +61,15 @@ def show_settings(pid):
reset_on_fork = ""
if policy & schedutils.SCHED_RESET_ON_FORK:
reset_on_fork = "|SCHED_RESET_ON_FORK"
- print '''pid %d's current scheduling policy: %s%s
-pid %d's current scheduling priority: %d''' % (pid, spolicy, reset_on_fork, pid, rtprio)
+ print('''pid %d's current scheduling policy: %s%s
+pid %d's current scheduling priority: %d''' % (pid, spolicy, reset_on_fork,
+ pid, rtprio))
def valid_policy_flag(policy, policy_flag):
if policy_flag == schedutils.SCHED_RESET_ON_FORK and \
policy not in (schedutils.SCHED_RR, schedutils.SCHED_FIFO):
- print "SCHED_RESET_ON_FORK flag is supported for SCHED_FIFO and SCHED_RR policies only"
+ print("SCHED_RESET_ON_FORK flag is supported for SCHED_FIFO and SCHED_RR policies only")
return False
return True
@@ -75,9 +77,9 @@ def valid_policy_flag(policy, policy_flag):
def change_settings(pid, policy, policy_flag, rtprio):
try:
schedutils.set_scheduler(pid, policy | policy_flag, rtprio)
- except SystemError, err:
- print "sched_setscheduler: %s" % err[1]
- print "failed to set pid %d's policy" % pid
+ except SystemError as err:
+ print("sched_setscheduler: %s" % err[1])
+ print("failed to set pid %d's policy" % pid)
def main():
diff --git a/ptaskset.py b/ptaskset.py
index de925a9..56fe7af 100755
--- a/ptaskset.py
+++ b/ptaskset.py
@@ -14,19 +14,20 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
+from __future__ import print_function
import os
import schedutils
import sys
def usage():
- print '''ptaskset (python-schedutils)
+ print('''ptaskset (python-schedutils)
usage: ptaskset [options] [mask | cpu-list] [pid | cmd [args...]]
set or get the affinity of a process
-p, --pid operate on existing given pid
-c, --cpu-list display and specify cpus in list format
- -h, --help display this help'''
+ -h, --help display this help''')
return
@@ -103,7 +104,7 @@ def cpustring_to_list(cpustr):
if len(ends) > 2:
raise "Syntax error"
if len(ends) == 2:
- cpu_list += range(int(ends[0]), int(ends[1]) + 1)
+ cpu_list += list(range(int(ends[0]), int(ends[1]) + 1))
else:
cpu_list += [int(ends[0])]
return list(set(cpu_list))
@@ -115,7 +116,7 @@ def show_settings(pid, when, cpu_list_mode):
mask = ",".join([str(a) for a in affinity])
else:
mask = ",".join(["%x" % a for a in hexbitmask(affinity)])
- print "pid %d's %s affinity mask: %s" % (pid, when, mask)
+ print("pid %d's %s affinity mask: %s" % (pid, when, mask))
def change_settings(pid, affinity, cpu_list_mode):
@@ -129,9 +130,9 @@ def change_settings(pid, affinity, cpu_list_mode):
try:
schedutils.set_affinity(pid, affinity)
- except SystemError, err:
- print "sched_setaffinity: %s" % err[1]
- print "failed to set pid %d's affinity" % pid
+ except SystemError as err:
+ print("sched_setaffinity: %s" % err[1])
+ print("failed to set pid %d's affinity" % pid)
def main():