Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d1caf92
Changed calling_in_this_thread restore mechanism in callOneCB from tr…
jasonimercer May 27, 2016
4fab862
Implement rospy.logXXX_throttle
wkentaro May 29, 2016
f11a2bc
More detailed help string for rostopic echo -p
Jun 5, 2016
5ab0601
add_rostest_gtest does now add the created gtest-target as a depende…
Jul 9, 2016
98c8bb8
Fix confusing copyright messages/dates
jspricke Apr 7, 2016
1d0b03c
update rosbag filter progress meter to use raw uncompressed input siz…
Aug 10, 2016
7651e21
fix unknown dependency
rhaschke Aug 19, 2016
c6e514b
Fix wrong type in docstring for rospy.Timer
wkentaro Aug 25, 2016
3d3ee03
set default values for min_space and min_space_str
dirk-thomas Sep 1, 2016
15e908b
fix test type handling (#722)
dirk-thomas Sep 19, 2016
d2c6200
remove invalid export
dirk-thomas Sep 21, 2016
8280e41
Add '#Include <vector>' to fix building on GCC-6
Peter-Levine Oct 4, 2016
ef5fbb4
Increase reqeust_queue_size for xmlrpc server (#849)
jonfink Jul 27, 2016
c1b388e
Fix BagMigrationException in migrate_raw
Oct 25, 2016
9fa1d07
Fixing logic issue causing cache not to be saved properly.
bponsler Nov 10, 2016
d539346
throw exception instead of accessing invalid memory
dirk-thomas Feb 1, 2017
579619b
[rostest] Fix type in hztest assertion (#992)
130s Feb 18, 2017
017aa89
[roslaunch] Indicating <node> tag when it is actually a <test> tag is…
130s Feb 16, 2017
48ef2a1
[rospy] made get_published_topics threadsafe (#958)
Jan 10, 2017
83d3935
fixed UDP block number when EAGAIN or EWOULDBLOCK (#957)
minsuu Jan 16, 2017
a198566
terminate underlying 'rosbag {play,record}' on SIGTERM
jwm Dec 16, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions clients/roscpp/src/libros/callback_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "ros/callback_queue.h"
#include "ros/assert.h"
#include <boost/scope_exit.hpp>

namespace ros
{
Expand Down Expand Up @@ -371,7 +372,17 @@ CallbackQueue::CallOneResult CallbackQueue::callOneCB(TLS* tls)
tls->calling_in_this_thread = id_info->id;

CallbackInterface::CallResult result = CallbackInterface::Invalid;
try {

{
// Ensure that thread id gets restored, even if callback throws.
// This is done with RAII rather than try-catch so that the source
// of the original exception is not masked in a crash report.
BOOST_SCOPE_EXIT(&tls, &last_calling)
{
tls->calling_in_this_thread = last_calling;
}
BOOST_SCOPE_EXIT_END

if (info.marked_for_removal)
{
tls->cb_it = tls->callbacks.erase(tls->cb_it);
Expand All @@ -382,14 +393,6 @@ CallbackQueue::CallOneResult CallbackQueue::callOneCB(TLS* tls)
result = cb->call();
}
}
catch (std::exception&)
{
// ensure that thread id gets restored, even in case of an exception
tls->calling_in_this_thread = last_calling;
throw;
}

tls->calling_in_this_thread = last_calling;

// Push TryAgain callbacks to the back of the shared queue
if (result == CallbackInterface::TryAgain && !info.marked_for_removal)
Expand Down
1 change: 1 addition & 0 deletions clients/roscpp/src/libros/transport/transport_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ int32_t TransportUDP::write(uint8_t* buffer, uint32_t size)
else
{
num_bytes = 0;
--this_block;
}
}
else if (num_bytes < (unsigned) sizeof(header))
Expand Down
4 changes: 4 additions & 0 deletions clients/rospy/src/rospy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from .core import is_shutdown, signal_shutdown, \
get_node_uri, get_ros_root, \
logdebug, logwarn, loginfo, logout, logerr, logfatal, \
logdebug_throttle, logwarn_throttle, loginfo_throttle, logerr_throttle, logfatal_throttle, \
parse_rosrpc_uri
from .exceptions import *
from .msg import AnyMsg
Expand Down Expand Up @@ -101,6 +102,9 @@
'logdebug',
'logwarn', 'loginfo',
'logout', 'logerr', 'logfatal',
'logdebug_throttle',
'logwarn_throttle', 'loginfo_throttle',
'logerr_throttle', 'logfatal_throttle',
'parse_rosrpc_uri',
'MasterProxy',
'NodeProxy',
Expand Down
66 changes: 66 additions & 0 deletions clients/rospy/src/rospy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@


import atexit
try:
import cPickle as pickle
except ImportError:
import pickle
import inspect
import logging
import os
import signal
Expand Down Expand Up @@ -149,6 +154,67 @@ def rospywarn(msg, *args):
logerror = logerr # alias logerr

logfatal = logging.getLogger('rosout').critical


class LoggingThrottle(object):

last_logging_time_table = {}

def __call__(self, caller_id, logging_func, period, msg):
"""Do logging specified message periodically.

- caller_id (str): Id to identify the caller
- logging_func (function): Function to do logging.
- period (float): Period to do logging in second unit.
- msg (object): Message to do logging.
"""
now = rospy.Time.now()

last_logging_time = self.last_logging_time_table.get(caller_id)

if (last_logging_time is None or
(now - last_logging_time) > rospy.Duration(period)):
logging_func(msg)
self.last_logging_time_table[caller_id] = now


_logging_throttle = LoggingThrottle()


def _frame_record_to_caller_id(frame_record):
frame, _, lineno, _, code, _ = frame_record
caller_id = (
inspect.getabsfile(frame),
lineno,
frame.f_lasti,
)
return pickle.dumps(caller_id)


def logdebug_throttle(period, msg):
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logdebug, period, msg)


def loginfo_throttle(period, msg):
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, loginfo, period, msg)


def logwarn_throttle(period, msg):
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logwarn, period, msg)


def logerr_throttle(period, msg):
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logerr, period, msg)


def logfatal_throttle(period, msg):
caller_id = _frame_record_to_caller_id(inspect.stack()[1])
_logging_throttle(caller_id, logfatal, period, msg)


#########################################################
# CONSTANTS
Expand Down
6 changes: 3 additions & 3 deletions clients/rospy/src/rospy/msproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def __init__(self, uri):
self._lock = Lock()

def __getattr__(self, key): #forward api calls to target
with self._lock:
f = getattr(self.target, key)
if key in _master_arg_remap:
remappings = _master_arg_remap[key]
else:
Expand All @@ -103,7 +101,9 @@ def wrappedF(*args, **kwds):
i = i + 1 #callerId does not count
#print "Remap %s => %s"%(args[i], rospy.names.resolve_name(args[i]))
args[i] = rospy.names.resolve_name(args[i])
return f(*args, **kwds)
with self._lock:
f = getattr(self.target, key)
return f(*args, **kwds)
return wrappedF

def __getitem__(self, key):
Expand Down
2 changes: 1 addition & 1 deletion clients/rospy/src/rospy/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def __init__(self, period, callback, oneshot=False):
"""
Constructor.
@param period: desired period between callbacks
@type period: rospy.Time
@type period: rospy.Duration
@param callback: callback to be called
@type callback: function taking rospy.TimerEvent
@param oneshot: if True, fire only once, otherwise fire continuously until shutdown is called [default: False]
Expand Down
2 changes: 1 addition & 1 deletion test/test_rosbag/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if(CATKIN_ENABLE_TESTING)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(double_pub EXCLUDE_FROM_ALL test/double_pub.cpp)
target_link_libraries(double_pub ${GTEST_LIBRARIES} ${catkin_LIBRARIES})
add_dependencies(double_pub rosgraph_msgs_genpy)
add_dependencies(double_pub ${rosgraph_msgs_EXPORTED_TARGETS})
if(TARGET tests)
add_dependencies(tests double_pub)
endif()
Expand Down
1 change: 0 additions & 1 deletion test/test_roscpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ endif()

catkin_package(
CATKIN_DEPENDS message_runtime rosconsole rosgraph_msgs std_msgs xmlrpcpp
DEPENDS Boost
)

if(CATKIN_ENABLE_TESTING)
Expand Down
2 changes: 1 addition & 1 deletion test/test_roscpp/test/src/latching_publisher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2NULLNULL8, Willow Garage, Inc.
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion test/test_roscpp/test/src/timer_callbacks.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2NULLNULL8, Willow Garage, Inc.
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion test/test_roscpp/test/src/wait_for_message.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2NULLNULL8, Willow Garage, Inc.
* Copyright (c) 2008, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
49 changes: 49 additions & 0 deletions test/test_rospy/test/rostest/test_rospy_client_online.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,55 @@ def test_log(self):
rospy.logfatal("test 4")
self.assert_("[FATAL]" in sys.stderr.getvalue())
self.assert_("test 4" in sys.stderr.getvalue())

# logXXX_throttle
for i in range(3):
sys.stdout = StringIO()
rospy.loginfo_throttle(3, "test 1")
if i == 0:
self.assert_("test 1" in sys.stdout.getvalue())
rospy.sleep(rospy.Duration(1))
elif i == 1:
self.assert_("" == sys.stdout.getvalue())
rospy.sleep(rospy.Duration(2))
else:
self.assert_("test 1" in sys.stdout.getvalue())

for i in range(3):
sys.stderr = StringIO()
rospy.logwarn_throttle(3, "test 2")
if i == 0:
self.assert_("test 2" in sys.stderr.getvalue())
rospy.sleep(rospy.Duration(1))
elif i == 1:
self.assert_("" == sys.stderr.getvalue())
rospy.sleep(rospy.Duration(2))
else:
self.assert_("test 2" in sys.stderr.getvalue())

for i in range(3):
sys.stderr = StringIO()
rospy.logerr_throttle(3, "test 3")
if i == 0:
self.assert_("test 3" in sys.stderr.getvalue())
rospy.sleep(rospy.Duration(1))
elif i == 1:
self.assert_("" == sys.stderr.getvalue())
rospy.sleep(rospy.Duration(2))
else:
self.assert_("test 3" in sys.stderr.getvalue())

for i in range(3):
sys.stderr = StringIO()
rospy.logfatal_throttle(3, "test 4")
if i == 0:
self.assert_("test 4" in sys.stderr.getvalue())
rospy.sleep(rospy.Duration(1))
elif i == 1:
self.assert_("" == sys.stderr.getvalue())
rospy.sleep(rospy.Duration(2))
else:
self.assert_("test 4" in sys.stderr.getvalue())
finally:
sys.stdout = real_stdout
sys.stderr = real_stderr
Expand Down
5 changes: 5 additions & 0 deletions test/test_rospy/test/unit/test_rospy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def test_rospy_api(self):
rospy.loginfo
rospy.logout #deprecated
rospy.logwarn
rospy.logdebug_throttle
rospy.logerr_throttle
rospy.logfatal_throttle
rospy.loginfo_throttle
rospy.logwarn_throttle
rospy.myargv
rospy.on_shutdown
rospy.parse_rosrpc_uri
Expand Down
9 changes: 8 additions & 1 deletion tools/rosbag/src/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ RecorderOptions::RecorderOptions() :
split(false),
max_size(0),
max_duration(-1.0),
node("")
node(""),
min_space(1024 * 1024 * 1024),
min_space_str("1G")
{
}

Expand Down Expand Up @@ -346,6 +348,11 @@ void Recorder::updateFilenames() {
if (options_.split)
parts.push_back(boost::lexical_cast<string>(split_count_));

if (parts.size() == 0)
{
throw BagException("Bag filename is empty (neither of these was specified: prefix, append_date, split)");
}

target_filename_ = parts[0];
for (unsigned int i = 1; i < parts.size(); i++)
target_filename_ += string("_") + parts[i];
Expand Down
2 changes: 1 addition & 1 deletion tools/rosbag/src/rosbag/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ def migrate_raw(self, msg_from, msg_to):
path = self.find_path(msg_from[4], msg_to[4])

if False in [sn.rule.valid for sn in path]:
raise BagMigrationException("Migrate called, but no valid migration path from [%s] to [%s]"%(msg_from._type, msg_to._type))
raise BagMigrationException("Migrate called, but no valid migration path from [%s] to [%s]"%(msg_from[0], msg_to[0]))

# Short cut to speed up case of matching md5sum:
if path == [] or msg_from[2] == msg_to[2]:
Expand Down
26 changes: 23 additions & 3 deletions tools/rosbag/src/rosbag/rosbag_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def handle_split(option, opt_str, value, parser):
print("Use of \"--split <MAX_SIZE>\" has been deprecated. Please use --split --size <MAX_SIZE> or --split --duration <MAX_DURATION>", file=sys.stderr)
parser.values.size = int(parser.rargs.pop(0))


def _stop_process(signum, frame, old_handler, process):
process.terminate()
if old_handler:
old_handler(signum, frame)


def record_cmd(argv):
parser = optparse.OptionParser(usage="rosbag record TOPIC1 [TOPIC2 TOPIC3 ...]",
description="Record a bag file with the contents of specified topics.",
Expand Down Expand Up @@ -121,9 +128,15 @@ def record_cmd(argv):

cmd.extend(args)

old_handler = signal.signal(
signal.SIGTERM,
lambda signum, frame: _stop_process(signum, frame, old_handler, process)
)
# Better way of handling it than os.execv
# This makes sure stdin handles are passed to the process.
subprocess.call(cmd)
process = subprocess.Popen(cmd)
process.wait()


def info_cmd(argv):
parser = optparse.OptionParser(usage='rosbag info [options] BAGFILE1 [BAGFILE2 BAGFILE3 ...]',
Expand Down Expand Up @@ -252,9 +265,16 @@ def play_cmd(argv):
cmd.extend(['--bags'])

cmd.extend(args)

old_handler = signal.signal(
signal.SIGTERM,
lambda signum, frame: _stop_process(signum, frame, old_handler, process)
)
# Better way of handling it than os.execv
# This makes sure stdin handles are passed to the process.
subprocess.call(cmd)
process = subprocess.Popen(cmd)
process.wait()


def filter_cmd(argv):
def expr_eval(expr):
Expand Down Expand Up @@ -304,7 +324,7 @@ def eval_fn(topic, m, t):
return

try:
meter = ProgressMeter(outbag_filename, inbag.size)
meter = ProgressMeter(outbag_filename, inbag._uncompressed_size)
total_bytes = 0

if options.verbose_pattern:
Expand Down
1 change: 1 addition & 0 deletions tools/rosconsole/include/ros/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <cstdarg>
#include <ros/macros.h>
#include <map>
#include <vector>

#ifdef ROSCONSOLE_BACKEND_LOG4CXX
#include "log4cxx/level.h"
Expand Down
3 changes: 3 additions & 0 deletions tools/rosgraph/src/rosgraph/xmlrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ def __init__(self, addr, log_requests=1):
# to True to allow quick restart on the same port. This is equivalent
# to calling setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
self.allow_reuse_address = True
# Increase request_queue_size to handle issues with many simultaneous
# connections in OSX 10.11
self.request_queue_size = min(socket.SOMAXCONN, 128)
if rosgraph.network.use_ipv6():
logger = logging.getLogger('xmlrpc')
# The XMLRPC library does not support IPv6 out of the box
Expand Down
Loading