Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rostopic hz and bw in Python 3 #1126

Merged
merged 7 commits into from
Aug 15, 2017
22 changes: 8 additions & 14 deletions tools/rostopic/src/rostopic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,11 @@ def __init__(self, window_size=100):
self.lock = threading.Lock()
self.last_printed_tn = 0
self.sizes =[]
self.times =[]
self.window_size = window_size or 100

self.times =[]
if window_size < 0:
window_size = 100
self.window_size = window_size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this logic change necessary for Python 3 support?


def callback(self, data):
"""ros sub callback"""
with self.lock:
Expand Down Expand Up @@ -1488,11 +1490,7 @@ def _rostopic_cmd_hz(argv):
if len(args) == 0:
parser.error("topic must be specified")
try:
if options.window_size != -1:
import string
window_size = string.atoi(options.window_size)
else:
window_size = options.window_size
window_size = int(options.window_size)
except:
parser.error("window size must be an integer")

Expand Down Expand Up @@ -1532,19 +1530,15 @@ def _rostopic_cmd_bw(argv=sys.argv):
from optparse import OptionParser
parser = OptionParser(usage="usage: %prog bw /topic", prog=NAME)
parser.add_option("-w", "--window",
dest="window_size", default=None,
dest="window_size", default=-1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change necessary for Python 3 support? None seems to be a perfectly reasonable default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not required but I did this for simplification of the following logic for converting window_size to int since int(None) is not allowed. I can check for None there instead if that seems better.

help="window size, in # of messages, for calculating rate", metavar="WINDOW")
options, args = parser.parse_args(args)
if len(args) == 0:
parser.error("topic must be specified")
if len(args) > 1:
parser.error("you may only specify one input topic")
try:
if options.window_size:
import string
window_size = string.atoi(options.window_size)
else:
window_size = options.window_size
window_size = int(options.window_size)
except:
parser.error("window size must be an integer")
topic = rosgraph.names.script_resolve_name('rostopic', args[0])
Expand Down